mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Merge pull request #10177 from peppy/fix-import-tests-waiting
Fix import tests not waiting long enough before performing migration
This commit is contained in:
commit
7eba30642e
@ -28,7 +28,7 @@ using FileInfo = System.IO.FileInfo;
|
||||
namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImportBeatmapTest
|
||||
public class ImportBeatmapTest : ImportTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestImportWhenClosed()
|
||||
@ -38,7 +38,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
await LoadOszIntoOsu(loadOsu(host));
|
||||
await LoadOszIntoOsu(LoadOsuIntoHost(host));
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -55,7 +55,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await LoadOszIntoOsu(osu);
|
||||
|
||||
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await LoadOszIntoOsu(osu);
|
||||
var importedSecondTime = await LoadOszIntoOsu(osu);
|
||||
@ -102,7 +102,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -160,7 +160,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -211,7 +211,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -263,7 +263,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await LoadOszIntoOsu(osu);
|
||||
|
||||
@ -314,7 +314,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Interlocked.Increment(ref loggedExceptionCount);
|
||||
};
|
||||
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
// ReSharper disable once AccessToModifiedClosure
|
||||
@ -382,7 +382,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await LoadOszIntoOsu(osu);
|
||||
|
||||
@ -410,7 +410,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await LoadOszIntoOsu(osu);
|
||||
|
||||
@ -444,7 +444,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
@ -504,7 +504,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Assert.IsTrue(host.IsPrimaryInstance);
|
||||
Assert.IsFalse(client.IsPrimaryInstance);
|
||||
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -530,7 +530,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
using (File.OpenRead(temp))
|
||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||
@ -552,7 +552,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -594,7 +594,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -639,7 +639,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -693,7 +693,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
@ -723,7 +723,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
@ -765,7 +765,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
||||
@ -792,7 +792,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
||||
@ -863,14 +863,6 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
Assert.AreEqual(expected, osu.Dependencies.Get<FileStore>().QueryFiles(f => f.ReferenceCount == 1).Count());
|
||||
}
|
||||
|
||||
private OsuGameBase loadOsu(GameHost host)
|
||||
{
|
||||
var osu = new OsuGameBase();
|
||||
Task.Run(() => host.Run(osu));
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
return osu;
|
||||
}
|
||||
|
||||
private static void ensureLoaded(OsuGameBase osu, int timeout = 60000)
|
||||
{
|
||||
IEnumerable<BeatmapSetInfo> resultSets = null;
|
||||
|
@ -4,18 +4,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
[TestFixture]
|
||||
public class ImportCollectionsTest
|
||||
public class ImportCollectionsTest : ImportTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestImportEmptyDatabase()
|
||||
@ -24,7 +21,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
await osu.CollectionManager.Import(new MemoryStream());
|
||||
|
||||
@ -44,7 +41,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
@ -70,7 +67,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host, true);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
@ -101,7 +98,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += setException;
|
||||
|
||||
var osu = loadOsu(host, true);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
@ -135,7 +132,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host, true);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||
|
||||
@ -156,7 +153,7 @@ namespace osu.Game.Tests.Collections.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host, true);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
||||
|
||||
@ -172,50 +169,5 @@ namespace osu.Game.Tests.Collections.IO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TestOsuGameBase loadOsu(GameHost host, bool withBeatmap = false)
|
||||
{
|
||||
var osu = new TestOsuGameBase(withBeatmap);
|
||||
|
||||
#pragma warning disable 4014
|
||||
Task.Run(() => host.Run(osu));
|
||||
#pragma warning restore 4014
|
||||
|
||||
waitForOrAssert(() => osu.IsLoaded, @"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);
|
||||
});
|
||||
|
||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||
}
|
||||
|
||||
private class TestOsuGameBase : OsuGameBase
|
||||
{
|
||||
public CollectionManager CollectionManager { get; private set; }
|
||||
|
||||
private readonly bool withBeatmap;
|
||||
|
||||
public TestOsuGameBase(bool withBeatmap)
|
||||
{
|
||||
this.withBeatmap = withBeatmap;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
// Beatmap must be imported before the collection manager is loaded.
|
||||
if (withBeatmap)
|
||||
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||
|
||||
AddInternal(CollectionManager = new CollectionManager(Storage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
66
osu.Game.Tests/ImportTest.cs
Normal file
66
osu.Game.Tests/ImportTest.cs
Normal file
@ -0,0 +1,66 @@
|
||||
// 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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Collections;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests
|
||||
{
|
||||
public abstract class ImportTest
|
||||
{
|
||||
protected virtual TestOsuGameBase LoadOsuIntoHost(GameHost host, bool withBeatmap = false)
|
||||
{
|
||||
var osu = new TestOsuGameBase(withBeatmap);
|
||||
Task.Run(() => host.Run(osu));
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||
}
|
||||
|
||||
public class TestOsuGameBase : OsuGameBase
|
||||
{
|
||||
public CollectionManager CollectionManager { get; private set; }
|
||||
|
||||
private readonly bool withBeatmap;
|
||||
|
||||
public TestOsuGameBase(bool withBeatmap)
|
||||
{
|
||||
this.withBeatmap = withBeatmap;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
// Beatmap must be imported before the collection manager is loaded.
|
||||
if (withBeatmap)
|
||||
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||
|
||||
AddInternal(CollectionManager = new CollectionManager(Storage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,8 +4,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.CompilerServices;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -17,18 +16,18 @@ using osu.Game.IO;
|
||||
namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
[TestFixture]
|
||||
public class CustomDataDirectoryTest
|
||||
public class CustomDataDirectoryTest : ImportTest
|
||||
{
|
||||
[Test]
|
||||
public void TestDefaultDirectory()
|
||||
{
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestDefaultDirectory)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));
|
||||
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var storage = osu.Dependencies.Get<Storage>();
|
||||
|
||||
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
|
||||
@ -45,14 +44,14 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (var host = new CustomTestHeadlessGameHost(nameof(TestCustomDirectory)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
|
||||
storageConfig.Set(StorageConfig.FullPath, customPath);
|
||||
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
// switch to DI'd storage
|
||||
var storage = osu.Dependencies.Get<Storage>();
|
||||
@ -71,14 +70,14 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (var host = new CustomTestHeadlessGameHost(nameof(TestSubDirectoryLookup)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
|
||||
storageConfig.Set(StorageConfig.FullPath, customPath);
|
||||
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
// switch to DI'd storage
|
||||
var storage = osu.Dependencies.Get<Storage>();
|
||||
@ -104,13 +103,13 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigration)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));
|
||||
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
var storage = osu.Dependencies.Get<Storage>();
|
||||
|
||||
// Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
|
||||
@ -165,11 +164,11 @@ namespace osu.Game.Tests.NonVisual
|
||||
string customPath = prepareCustomPath();
|
||||
string customPath2 = prepareCustomPath("-2");
|
||||
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationBetweenTwoTargets)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
const string database_filename = "client.db";
|
||||
|
||||
@ -194,11 +193,11 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSameTargetFails)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||
Assert.Throws<ArgumentException>(() => osu.Migrate(customPath));
|
||||
@ -215,11 +214,11 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToNestedTargetFails)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||
|
||||
@ -244,11 +243,11 @@ namespace osu.Game.Tests.NonVisual
|
||||
{
|
||||
string customPath = prepareCustomPath();
|
||||
|
||||
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSeeminglyNestedTarget)))
|
||||
using (var host = new CustomTestHeadlessGameHost())
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||
|
||||
@ -268,25 +267,6 @@ namespace osu.Game.Tests.NonVisual
|
||||
}
|
||||
}
|
||||
|
||||
private OsuGameBase loadOsu(GameHost host)
|
||||
{
|
||||
var osu = new OsuGameBase();
|
||||
Task.Run(() => host.Run(osu));
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
|
||||
return osu;
|
||||
}
|
||||
|
||||
private static void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
||||
{
|
||||
Task task = Task.Run(() =>
|
||||
{
|
||||
while (!result()) Thread.Sleep(200);
|
||||
});
|
||||
|
||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||
}
|
||||
|
||||
private static string getDefaultLocationFor(string testTypeName)
|
||||
{
|
||||
string path = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testTypeName);
|
||||
@ -307,14 +287,14 @@ namespace osu.Game.Tests.NonVisual
|
||||
return path;
|
||||
}
|
||||
|
||||
public class CustomTestHeadlessGameHost : HeadlessGameHost
|
||||
public class CustomTestHeadlessGameHost : CleanRunHeadlessGameHost
|
||||
{
|
||||
public Storage InitialStorage { get; }
|
||||
|
||||
public CustomTestHeadlessGameHost(string name)
|
||||
: base(name)
|
||||
public CustomTestHeadlessGameHost([CallerMemberName] string callingMethodName = @"")
|
||||
: base(callingMethodName: callingMethodName)
|
||||
{
|
||||
string defaultStorageLocation = getDefaultLocationFor(name);
|
||||
string defaultStorageLocation = getDefaultLocationFor(callingMethodName);
|
||||
|
||||
InitialStorage = new DesktopStorage(defaultStorageLocation, this);
|
||||
InitialStorage.DeleteDirectory(string.Empty);
|
||||
|
@ -5,7 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -17,12 +16,11 @@ using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
public class ImportScoreTest
|
||||
public class ImportScoreTest : ImportTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestBasicImport()
|
||||
@ -31,7 +29,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
var toImport = new ScoreInfo
|
||||
{
|
||||
@ -45,7 +43,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
OnlineScoreID = 12345,
|
||||
};
|
||||
|
||||
var imported = await loadIntoOsu(osu, toImport);
|
||||
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||
|
||||
Assert.AreEqual(toImport.Rank, imported.Rank);
|
||||
Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
|
||||
@ -70,14 +68,14 @@ namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
var toImport = new ScoreInfo
|
||||
{
|
||||
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
|
||||
};
|
||||
|
||||
var imported = await loadIntoOsu(osu, toImport);
|
||||
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||
|
||||
Assert.IsTrue(imported.Mods.Any(m => m is OsuModHardRock));
|
||||
Assert.IsTrue(imported.Mods.Any(m => m is OsuModDoubleTime));
|
||||
@ -96,7 +94,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
var toImport = new ScoreInfo
|
||||
{
|
||||
@ -107,7 +105,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
}
|
||||
};
|
||||
|
||||
var imported = await loadIntoOsu(osu, toImport);
|
||||
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||
|
||||
Assert.AreEqual(toImport.Statistics[HitResult.Perfect], imported.Statistics[HitResult.Perfect]);
|
||||
Assert.AreEqual(toImport.Statistics[HitResult.Miss], imported.Statistics[HitResult.Miss]);
|
||||
@ -126,7 +124,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
var toImport = new ScoreInfo
|
||||
{
|
||||
@ -138,7 +136,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
}
|
||||
};
|
||||
|
||||
var imported = await loadIntoOsu(osu, toImport);
|
||||
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||
|
||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||
@ -146,7 +144,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.Beatmap.ID)));
|
||||
Assert.That(scoreManager.Query(s => s.ID == imported.ID).DeletePending, Is.EqualTo(true));
|
||||
|
||||
var secondImport = await loadIntoOsu(osu, imported);
|
||||
var secondImport = await loadScoreIntoOsu(osu, imported);
|
||||
Assert.That(secondImport, Is.Null);
|
||||
}
|
||||
finally
|
||||
@ -163,9 +161,9 @@ namespace osu.Game.Tests.Scores.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host, true);
|
||||
|
||||
await loadIntoOsu(osu, new ScoreInfo { OnlineScoreID = 2 }, new TestArchiveReader());
|
||||
await loadScoreIntoOsu(osu, new ScoreInfo { OnlineScoreID = 2 }, new TestArchiveReader());
|
||||
|
||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||
|
||||
@ -179,7 +177,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<ScoreInfo> loadIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
||||
private async Task<ScoreInfo> loadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
||||
{
|
||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||
|
||||
@ -192,33 +190,6 @@ namespace osu.Game.Tests.Scores.IO
|
||||
return scoreManager.GetAllUsableScores().FirstOrDefault();
|
||||
}
|
||||
|
||||
private async Task<OsuGameBase> loadOsu(GameHost host)
|
||||
{
|
||||
var osu = new OsuGameBase();
|
||||
|
||||
#pragma warning disable 4014
|
||||
Task.Run(() => host.Run(osu));
|
||||
#pragma warning restore 4014
|
||||
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
|
||||
var beatmapFile = TestResources.GetTestBeatmapForImport();
|
||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||
await beatmapManager.Import(beatmapFile);
|
||||
|
||||
return osu;
|
||||
}
|
||||
|
||||
private void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
||||
{
|
||||
Task task = Task.Run(() =>
|
||||
{
|
||||
while (!result()) Thread.Sleep(200);
|
||||
});
|
||||
|
||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||
}
|
||||
|
||||
private class TestArchiveReader : ArchiveReader
|
||||
{
|
||||
public TestArchiveReader()
|
||||
|
@ -4,20 +4,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Tests.Resources;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
public class ImportSkinTest
|
||||
public class ImportSkinTest : ImportTest
|
||||
{
|
||||
[Test]
|
||||
public async Task TestBasicImport()
|
||||
@ -26,9 +23,9 @@ namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||
|
||||
Assert.That(imported.Name, Is.EqualTo("test skin"));
|
||||
Assert.That(imported.Creator, Is.EqualTo("skinner"));
|
||||
@ -47,10 +44,10 @@ namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin2.osk"));
|
||||
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin2.osk"));
|
||||
|
||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(1));
|
||||
@ -72,11 +69,11 @@ namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
// if a user downloads two skins that do have skin.ini files but don't have any creator metadata in the skin.ini, they should both import separately just for safety.
|
||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||
|
||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
||||
@ -98,10 +95,10 @@ namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = await loadOsu(host);
|
||||
var osu = LoadOsuIntoHost(host);
|
||||
|
||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2", "skinner"), "skin.osk"));
|
||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2.1", "skinner"), "skin2.osk"));
|
||||
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2", "skinner"), "skin.osk"));
|
||||
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2.1", "skinner"), "skin2.osk"));
|
||||
|
||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
||||
@ -141,37 +138,10 @@ namespace osu.Game.Tests.Skins.IO
|
||||
return stream;
|
||||
}
|
||||
|
||||
private async Task<SkinInfo> loadIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
||||
private async Task<SkinInfo> loadSkinIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
||||
{
|
||||
var skinManager = osu.Dependencies.Get<SkinManager>();
|
||||
return await skinManager.Import(archive);
|
||||
}
|
||||
|
||||
private async Task<OsuGameBase> loadOsu(GameHost host)
|
||||
{
|
||||
var osu = new OsuGameBase();
|
||||
|
||||
#pragma warning disable 4014
|
||||
Task.Run(() => host.Run(osu));
|
||||
#pragma warning restore 4014
|
||||
|
||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||
|
||||
var beatmapFile = TestResources.GetTestBeatmapForImport();
|
||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||
await beatmapManager.Import(beatmapFile);
|
||||
|
||||
return osu;
|
||||
}
|
||||
|
||||
private void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
||||
{
|
||||
Task task = Task.Run(() =>
|
||||
{
|
||||
while (!result()) Thread.Sleep(200);
|
||||
});
|
||||
|
||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user