Avoid leaving left-over files after test run completes

This commit is contained in:
Dean Herbert
2022-07-26 14:56:41 +09:00
parent a7598c62ac
commit 59d3cc52c4
4 changed files with 23 additions and 35 deletions

View File

@ -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(() =>
{