1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Ensure CustomDataDirectoryTest methods use a fresh directory to avoid IO errors

Resolves test failures like https://github.com/ppy/osu/runs/4592088736?check_suite_focus=true.
This commit is contained in:
Dean Herbert 2021-12-21 18:42:37 +09:00
parent d7136d6b48
commit 4a3a5054fd

View File

@ -61,6 +61,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -94,6 +95,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -160,6 +162,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -168,7 +171,7 @@ namespace osu.Game.Tests.NonVisual
public void TestMigrationBetweenTwoTargets()
{
string customPath = prepareCustomPath();
string customPath2 = prepareCustomPath("-2");
string customPath2 = prepareCustomPath();
using (var host = new CustomTestHeadlessGameHost())
{
@ -185,7 +188,7 @@ namespace osu.Game.Tests.NonVisual
Assert.That(File.Exists(Path.Combine(customPath2, database_filename)));
// some files may have been left behind for whatever reason, but that's not what we're testing here.
customPath = prepareCustomPath();
cleanupPath(customPath);
Assert.DoesNotThrow(() => osu.Migrate(customPath));
Assert.That(File.Exists(Path.Combine(customPath, database_filename)));
@ -193,6 +196,8 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
cleanupPath(customPath2);
}
}
}
@ -214,6 +219,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -243,6 +249,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -272,6 +279,7 @@ namespace osu.Game.Tests.NonVisual
finally
{
host.Exit();
cleanupPath(customPath);
}
}
}
@ -286,14 +294,18 @@ namespace osu.Game.Tests.NonVisual
return path;
}
private string prepareCustomPath(string suffix = "")
private static string prepareCustomPath() => Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, $"custom-path-{Guid.NewGuid()}");
private static void cleanupPath(string path)
{
string path = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, $"custom-path{suffix}");
if (Directory.Exists(path))
Directory.Delete(path, true);
return path;
try
{
if (Directory.Exists(path))
Directory.Delete(path, true);
}
catch
{
}
}
public class CustomTestHeadlessGameHost : CleanRunHeadlessGameHost