mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 07:42:55 +08:00
Fix test failures
This commit is contained in:
parent
b7ca003928
commit
8e2f5d4ea8
@ -8,8 +8,8 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Collections;
|
using osu.Game.Collections;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
@ -21,11 +21,11 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportEmptyDatabase()
|
public async Task TestImportEmptyDatabase()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportEmptyDatabase"))
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = loadOsu(host);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
await collectionManager.Import(new MemoryStream());
|
await collectionManager.Import(new MemoryStream());
|
||||||
@ -42,11 +42,11 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportWithNoBeatmaps()
|
public async Task TestImportWithNoBeatmaps()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWithNoBeatmaps"))
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = loadOsu(host);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
@ -69,11 +69,11 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportWithBeatmaps()
|
public async Task TestImportWithBeatmaps()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportWithBeatmaps"))
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host, true);
|
var osu = loadOsu(host, true);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
@ -99,13 +99,13 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
bool exceptionThrown = false;
|
bool exceptionThrown = false;
|
||||||
UnhandledExceptionEventHandler setException = (_, __) => exceptionThrown = true;
|
UnhandledExceptionEventHandler setException = (_, __) => exceptionThrown = true;
|
||||||
|
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportMalformedDatabase"))
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += setException;
|
AppDomain.CurrentDomain.UnhandledException += setException;
|
||||||
|
|
||||||
var osu = await loadOsu(host, true);
|
var osu = loadOsu(host, true);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
|
|
||||||
@ -137,11 +137,11 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
[Test]
|
[Test]
|
||||||
public async Task TestSaveAndReload()
|
public async Task TestSaveAndReload()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestSaveAndReload"))
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host, true);
|
var osu = loadOsu(host, true);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await collectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
@ -163,7 +163,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host, true);
|
var osu = loadOsu(host, true);
|
||||||
|
|
||||||
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
|
|
||||||
@ -182,9 +182,9 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OsuGameBase> loadOsu(GameHost host, bool withBeatmap = false)
|
private OsuGameBase loadOsu(GameHost host, bool withBeatmap = false)
|
||||||
{
|
{
|
||||||
var osu = new OsuGameBase();
|
var osu = new TestOsuGameBase(withBeatmap);
|
||||||
|
|
||||||
#pragma warning disable 4014
|
#pragma warning disable 4014
|
||||||
Task.Run(() => host.Run(osu));
|
Task.Run(() => host.Run(osu));
|
||||||
@ -192,12 +192,8 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
|
|
||||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||||
|
|
||||||
if (withBeatmap)
|
var collectionManager = osu.Dependencies.Get<BeatmapCollectionManager>();
|
||||||
{
|
waitForOrAssert(() => collectionManager.DatabaseLoaded, "Collection database did not load in a reasonable amount of time");
|
||||||
var beatmapFile = TestResources.GetTestBeatmapForImport();
|
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
|
||||||
await beatmapManager.Import(beatmapFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return osu;
|
return osu;
|
||||||
}
|
}
|
||||||
@ -211,5 +207,24 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
|
|
||||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestOsuGameBase : OsuGameBase
|
||||||
|
{
|
||||||
|
private readonly bool withBeatmap;
|
||||||
|
|
||||||
|
public TestOsuGameBase(bool withBeatmap)
|
||||||
|
{
|
||||||
|
this.withBeatmap = withBeatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AddInternal(Drawable drawable)
|
||||||
|
{
|
||||||
|
// The beatmap must be imported just before the collection manager is loaded.
|
||||||
|
if (drawable is BeatmapCollectionManager && withBeatmap)
|
||||||
|
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||||
|
|
||||||
|
base.AddInternal(drawable);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ namespace osu.Game.Collections
|
|||||||
|
|
||||||
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
|
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the user's database has finished loading.
|
||||||
|
/// </summary>
|
||||||
|
public bool DatabaseLoaded { get; private set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
@ -86,6 +91,8 @@ namespace osu.Game.Collections
|
|||||||
using (var stream = storage.GetStream(database_name))
|
using (var stream = storage.GetStream(database_name))
|
||||||
await import(stream);
|
await import(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseLoaded = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user