mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:43:05 +08:00
Avoid leaving left-over files after test run completes
This commit is contained in:
parent
a7598c62ac
commit
59d3cc52c4
@ -142,7 +142,6 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var beatmapSet = await importer.Import(new ImportTask(TestResources.GetTestBeatmapStream(), "renatus.osz"));
|
||||
|
||||
Assert.NotNull(beatmapSet);
|
||||
|
@ -32,31 +32,29 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestAccessAfterStorageMigrate()
|
||||
{
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target"))
|
||||
{
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
|
||||
Live<BeatmapInfo>? liveBeatmap = null;
|
||||
|
||||
realm.Run(r =>
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
r.Write(_ => r.Add(beatmap));
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
Live<BeatmapInfo>? liveBeatmap = null;
|
||||
|
||||
realm.Run(r =>
|
||||
{
|
||||
r.Write(_ => r.Add(beatmap));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
|
||||
using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target"))
|
||||
{
|
||||
migratedStorage.DeleteDirectory(string.Empty);
|
||||
|
||||
using (realm.BlockAllOperations("testing"))
|
||||
{
|
||||
storage.Migrate(migratedStorage);
|
||||
}
|
||||
|
||||
Assert.IsFalse(liveBeatmap?.PerformRead(l => l.Hidden));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -341,14 +339,12 @@ namespace osu.Game.Tests.Database
|
||||
liveBeatmap.PerformRead(resolved =>
|
||||
{
|
||||
// retrieval causes an implicit refresh. even changes that aren't related to the retrieval are fired at this point.
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
Assert.AreEqual(2, outerRealm.All<BeatmapInfo>().Count());
|
||||
Assert.AreEqual(1, changesTriggered);
|
||||
|
||||
// can access properties without a crash.
|
||||
Assert.IsFalse(resolved.Hidden);
|
||||
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
outerRealm.Write(r =>
|
||||
{
|
||||
// can use with the main context.
|
||||
|
@ -4,11 +4,11 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
@ -20,22 +20,15 @@ namespace osu.Game.Tests.Database
|
||||
[TestFixture]
|
||||
public abstract class RealmTest
|
||||
{
|
||||
private static readonly TemporaryNativeStorage storage;
|
||||
|
||||
static RealmTest()
|
||||
{
|
||||
storage = new TemporaryNativeStorage("realm-test");
|
||||
storage.DeleteDirectory(string.Empty);
|
||||
}
|
||||
|
||||
protected void RunTestWithRealm(Action<RealmAccess, OsuStorage> testAction, [CallerMemberName] string caller = "")
|
||||
protected void RunTestWithRealm([InstantHandle] Action<RealmAccess, OsuStorage> testAction, [CallerMemberName] string caller = "")
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller))
|
||||
{
|
||||
host.Run(new RealmTestGame(() =>
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var testStorage = new OsuStorage(host, storage.GetStorageForDirectory(caller));
|
||||
var defaultStorage = host.Storage;
|
||||
|
||||
var testStorage = new OsuStorage(host, defaultStorage);
|
||||
|
||||
using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME))
|
||||
{
|
||||
@ -58,7 +51,7 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
host.Run(new RealmTestGame(async () =>
|
||||
{
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
var testStorage = host.Storage;
|
||||
|
||||
using (var realm = new RealmAccess(testStorage, OsuGameBase.CLIENT_DATABASE_FILENAME))
|
||||
{
|
||||
@ -116,7 +109,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
private class RealmTestGame : Framework.Game
|
||||
{
|
||||
public RealmTestGame(Func<Task> work)
|
||||
public RealmTestGame([InstantHandle] Func<Task> work)
|
||||
{
|
||||
// ReSharper disable once AsyncVoidLambda
|
||||
Scheduler.Add(async () =>
|
||||
@ -126,7 +119,7 @@ namespace osu.Game.Tests.Database
|
||||
});
|
||||
}
|
||||
|
||||
public RealmTestGame(Action work)
|
||||
public RealmTestGame([InstantHandle] Action work)
|
||||
{
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -27,7 +28,6 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
||||
{
|
||||
var osu = new TestTournament(runOnLoadComplete: () =>
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default"));
|
||||
|
||||
using (var stream = storage.CreateFileSafely("bracket.json"))
|
||||
@ -85,7 +85,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
|
||||
|
||||
public new Task BracketLoadTask => base.BracketLoadTask;
|
||||
|
||||
public TestTournament(bool resetRuleset = false, Action runOnLoadComplete = null)
|
||||
public TestTournament(bool resetRuleset = false, [InstantHandle] Action runOnLoadComplete = null)
|
||||
{
|
||||
this.resetRuleset = resetRuleset;
|
||||
this.runOnLoadComplete = runOnLoadComplete;
|
||||
|
Loading…
Reference in New Issue
Block a user