1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Fix directory cleanup occurring too early during realm tests

This commit is contained in:
Dean Herbert 2022-06-30 16:02:46 +09:00
parent e89f220e9a
commit 10934450cc

View File

@ -44,8 +44,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestCustomDirectory() public void TestCustomDirectory()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
using (var storageConfig = new StorageConfigManager(host.InitialStorage)) using (var storageConfig = new StorageConfigManager(host.InitialStorage))
@ -63,7 +62,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -71,8 +69,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestSubDirectoryLookup() public void TestSubDirectoryLookup()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
using (var storageConfig = new StorageConfigManager(host.InitialStorage)) using (var storageConfig = new StorageConfigManager(host.InitialStorage))
@ -97,7 +94,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -105,8 +101,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigration() public void TestMigration()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -173,7 +168,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -181,9 +175,8 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigrationBetweenTwoTargets() public void TestMigrationBetweenTwoTargets()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
string customPath2 = prepareCustomPath(); using (prepareCustomPath(out string customPath2))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -205,8 +198,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
cleanupPath(customPath2);
} }
} }
} }
@ -214,8 +205,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigrationToSameTargetFails() public void TestMigrationToSameTargetFails()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -228,7 +218,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -236,9 +225,8 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigrationFailsOnExistingData() public void TestMigrationFailsOnExistingData()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
string customPath2 = prepareCustomPath(); using (prepareCustomPath(out string customPath2))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -267,8 +255,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
cleanupPath(customPath2);
} }
} }
} }
@ -276,8 +262,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigrationToNestedTargetFails() public void TestMigrationToNestedTargetFails()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -298,7 +283,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -306,8 +290,7 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestMigrationToSeeminglyNestedTarget() public void TestMigrationToSeeminglyNestedTarget()
{ {
string customPath = prepareCustomPath(); using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost()) using (var host = new CustomTestHeadlessGameHost())
{ {
try try
@ -328,7 +311,6 @@ namespace osu.Game.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
cleanupPath(customPath);
} }
} }
} }
@ -343,14 +325,17 @@ namespace osu.Game.Tests.NonVisual
return path; return path;
} }
private static string prepareCustomPath() => Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, $"custom-path-{Guid.NewGuid()}"); private static IDisposable prepareCustomPath(out string path)
{
path = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, $"custom-path-{Guid.NewGuid()}");
return new InvokeOnDisposal<string>(path, cleanupPath);
}
private static void cleanupPath(string path) private static void cleanupPath(string path)
{ {
try try
{ {
if (Directory.Exists(path)) if (Directory.Exists(path)) Directory.Delete(path, true);
Directory.Delete(path, true);
} }
catch catch
{ {