1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 05:52:54 +08:00

Add a method to recycle test storage between runs

This commit is contained in:
Dean Herbert 2020-01-28 19:44:32 +09:00
parent 99d5398262
commit 0e0c730095
2 changed files with 22 additions and 13 deletions

View File

@ -65,6 +65,8 @@ namespace osu.Game.Tests.Visual.Menus
game.Dispose();
}
RecycleLocalStorage();
game = new TestOsuGame(LocalStorage, API);
game.SetHost(host);

View File

@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual
protected new OsuScreenDependencies Dependencies { get; private set; }
private readonly Lazy<Storage> localStorage;
private Lazy<Storage> localStorage;
protected Storage LocalStorage => localStorage.Value;
private readonly Lazy<DatabaseContextFactory> contextFactory;
@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual
protected OsuTestScene()
{
localStorage = new Lazy<Storage>(() => new NativeStorage($"{GetType().Name}-{Guid.NewGuid()}"));
RecycleLocalStorage();
contextFactory = new Lazy<DatabaseContextFactory>(() =>
{
var factory = new DatabaseContextFactory(LocalStorage);
@ -104,6 +104,23 @@ namespace osu.Game.Tests.Visual
base.Content.Add(content = new DrawSizePreservingFillContainer());
}
public void RecycleLocalStorage()
{
if (localStorage?.IsValueCreated == true)
{
try
{
localStorage.Value.DeleteDirectory(".");
}
catch
{
// we don't really care if this fails; it will just leave folders lying around from test runs.
}
}
localStorage = new Lazy<Storage>(() => new NativeStorage($"{GetType().Name}-{Guid.NewGuid()}"));
}
[Resolved]
protected AudioManager Audio { get; private set; }
@ -131,17 +148,7 @@ namespace osu.Game.Tests.Visual
if (contextFactory.IsValueCreated)
contextFactory.Value.ResetDatabase();
if (localStorage.IsValueCreated)
{
try
{
localStorage.Value.DeleteDirectory(".");
}
catch
{
// we don't really care if this fails; it will just leave folders lying around from test runs.
}
}
RecycleLocalStorage();
}
protected override ITestSceneTestRunner CreateRunner() => new OsuTestSceneTestRunner();