diff --git a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs index 8a063b3c6e..8d15be44fa 100644 --- a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs +++ b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs @@ -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