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
1 changed files with 16 additions and 31 deletions

View File

@ -44,8 +44,7 @@ public void TestDefaultDirectory()
[Test]
public void TestCustomDirectory()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
@ -63,7 +62,6 @@ public void TestCustomDirectory()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -71,8 +69,7 @@ public void TestCustomDirectory()
[Test]
public void TestSubDirectoryLookup()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
@ -97,7 +94,6 @@ public void TestSubDirectoryLookup()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -105,8 +101,7 @@ public void TestSubDirectoryLookup()
[Test]
public void TestMigration()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -173,7 +168,6 @@ public void TestMigration()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -181,9 +175,8 @@ public void TestMigration()
[Test]
public void TestMigrationBetweenTwoTargets()
{
string customPath = prepareCustomPath();
string customPath2 = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (prepareCustomPath(out string customPath2))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -205,8 +198,6 @@ public void TestMigrationBetweenTwoTargets()
finally
{
host.Exit();
cleanupPath(customPath);
cleanupPath(customPath2);
}
}
}
@ -214,8 +205,7 @@ public void TestMigrationBetweenTwoTargets()
[Test]
public void TestMigrationToSameTargetFails()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -228,7 +218,6 @@ public void TestMigrationToSameTargetFails()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -236,9 +225,8 @@ public void TestMigrationToSameTargetFails()
[Test]
public void TestMigrationFailsOnExistingData()
{
string customPath = prepareCustomPath();
string customPath2 = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (prepareCustomPath(out string customPath2))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -267,8 +255,6 @@ public void TestMigrationFailsOnExistingData()
finally
{
host.Exit();
cleanupPath(customPath);
cleanupPath(customPath2);
}
}
}
@ -276,8 +262,7 @@ public void TestMigrationFailsOnExistingData()
[Test]
public void TestMigrationToNestedTargetFails()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -298,7 +283,6 @@ public void TestMigrationToNestedTargetFails()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -306,8 +290,7 @@ public void TestMigrationToNestedTargetFails()
[Test]
public void TestMigrationToSeeminglyNestedTarget()
{
string customPath = prepareCustomPath();
using (prepareCustomPath(out string customPath))
using (var host = new CustomTestHeadlessGameHost())
{
try
@ -328,7 +311,6 @@ public void TestMigrationToSeeminglyNestedTarget()
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -343,14 +325,17 @@ private static string getDefaultLocationFor(CustomTestHeadlessGameHost host)
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)
{
try
{
if (Directory.Exists(path))
Directory.Delete(path, true);
if (Directory.Exists(path)) Directory.Delete(path, true);
}
catch
{