mirror of
https://github.com/ppy/osu.git
synced 2026-05-19 01:10:05 +08:00
a996261304
It's been a while. Notes: - `SharpCompress` usages changed a bit. Manually adjusted these, mostly just renames or adjusted parameters. - nUnit 3 -> 4 migrated using https://gist.github.com/peppy/07994386d793a117350cb5f24b156585. there's a mode in this script to update to the newer `Assert.That` syntax but it requires fixes and couldn't really be bothered. - DeepEqual nuked as the only usage was on a disabled test. The reason it's disabled has been merged upstream, but it's failing for other (realm) reasons which I don't think is worthwhile to investigate for now. - This bumps Moq. I think the author is back in a sensible headspace and the new version has the stupid shit removed, so probably okay? Nice to be on a level playing field with packages for once in a long time. - Automapper is silly, but we've discussed this elsewhere. - `TestRealmKeyBindingStore` failures are a wildcard, but fixed by using a more standardised testing method. Dunno why, don't care. --------- Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework.Legacy;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Extensions;
|
|
using osu.Framework.Platform;
|
|
using osu.Game.Database;
|
|
using osu.Game.Online.API;
|
|
using osu.Game.Tests.Resources;
|
|
|
|
namespace osu.Game.Tests
|
|
{
|
|
public abstract partial class ImportTest
|
|
{
|
|
protected virtual TestOsuGameBase LoadOsuIntoHost(GameHost host, bool withBeatmap = false)
|
|
{
|
|
var osu = new TestOsuGameBase(withBeatmap);
|
|
Task.Factory.StartNew(() => host.Run(osu), TaskCreationOptions.LongRunning)
|
|
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
|
|
|
|
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
|
|
bool ready = false;
|
|
// wait for two update frames to be executed. this ensures that all components have had a change to run LoadComplete and hopefully avoid
|
|
// database access (GlobalActionContainer is one to do this).
|
|
host.UpdateThread.Scheduler.Add(() => host.UpdateThread.Scheduler.Add(() => ready = true));
|
|
|
|
waitForOrAssert(() => ready, @"osu! failed to start in a reasonable amount of time");
|
|
|
|
return osu;
|
|
}
|
|
|
|
private void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
|
{
|
|
Task task = Task.Run(() =>
|
|
{
|
|
while (!result()) Thread.Sleep(200);
|
|
});
|
|
|
|
ClassicAssert.True(task.Wait(timeout), failureMessage);
|
|
}
|
|
|
|
public partial class TestOsuGameBase : OsuGameBase
|
|
{
|
|
public RealmAccess Realm => Dependencies.Get<RealmAccess>();
|
|
public new IAPIProvider API => base.API;
|
|
|
|
private readonly bool withBeatmap;
|
|
|
|
public TestOsuGameBase(bool withBeatmap)
|
|
{
|
|
this.withBeatmap = withBeatmap;
|
|
|
|
base.API = new DummyAPIAccess();
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
// Beatmap must be imported before the collection manager is loaded.
|
|
if (withBeatmap)
|
|
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).WaitSafely();
|
|
|
|
// the logic for setting the initial ruleset exists in OsuGame rather than OsuGameBase.
|
|
// the ruleset bindable is not meant to be nullable, so assign any ruleset in here.
|
|
Ruleset.Value = RulesetStore.AvailableRulesets.First();
|
|
}
|
|
}
|
|
}
|
|
}
|