2021-07-29 16:53:08 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-29 16:53:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests.NonVisual
|
|
|
|
{
|
|
|
|
public abstract class TournamentHostTest
|
|
|
|
{
|
|
|
|
public static TournamentGameBase LoadTournament(GameHost host, TournamentGameBase tournament = null)
|
|
|
|
{
|
|
|
|
tournament ??= new TournamentGameBase();
|
2021-10-12 08:13:36 +00:00
|
|
|
Task.Factory.StartNew(() => host.Run(tournament), TaskCreationOptions.LongRunning)
|
2021-07-29 16:53:08 +00:00
|
|
|
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
|
|
|
|
WaitForOrAssert(() => tournament.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
|
|
return tournament;
|
|
|
|
}
|
|
|
|
|
2021-11-23 05:38:37 +00:00
|
|
|
public static void WaitForOrAssert(Func<bool> result, string failureMessage, int timeout = 30000)
|
2021-07-29 16:53:08 +00:00
|
|
|
{
|
|
|
|
Task task = Task.Run(() =>
|
|
|
|
{
|
|
|
|
while (!result()) Thread.Sleep(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|