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

Merge pull request #15754 from peppy/tournament-test-isolation-clear-previuos

Fix tournament tests potentially using data left over from previous runs
This commit is contained in:
Dan Balasescu 2021-11-23 17:10:41 +09:00 committed by GitHub
commit 216c18b0bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 13 deletions

View File

@ -38,7 +38,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
{ {
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file. using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file.
{ {
string osuDesktopStorage = basePath(nameof(TestCustomDirectory)); string osuDesktopStorage = PrepareBasePath(nameof(TestCustomDirectory));
const string custom_tournament = "custom"; const string custom_tournament = "custom";
// need access before the game has constructed its own storage yet. // need access before the game has constructed its own storage yet.
@ -60,6 +60,15 @@ namespace osu.Game.Tournament.Tests.NonVisual
finally finally
{ {
host.Exit(); host.Exit();
try
{
if (Directory.Exists(osuDesktopStorage))
Directory.Delete(osuDesktopStorage, true);
}
catch
{
}
} }
} }
} }
@ -69,7 +78,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
{ {
using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration. using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration.
{ {
string osuRoot = basePath(nameof(TestMigration)); string osuRoot = PrepareBasePath(nameof(TestMigration));
string configFile = Path.Combine(osuRoot, "tournament.ini"); string configFile = Path.Combine(osuRoot, "tournament.ini");
if (File.Exists(configFile)) if (File.Exists(configFile))
@ -136,18 +145,29 @@ namespace osu.Game.Tournament.Tests.NonVisual
} }
finally finally
{ {
host.Exit();
try try
{ {
host.Storage.Delete("tournament.ini"); if (Directory.Exists(osuRoot))
host.Storage.DeleteDirectory("tournaments"); Directory.Delete(osuRoot, true);
}
catch
{
} }
catch { }
host.Exit();
} }
} }
} }
private string basePath(string testInstance) => Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance); public static string PrepareBasePath(string testInstance)
{
string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testInstance);
// manually clean before starting in case there are left-over files at the test site.
if (Directory.Exists(basePath))
Directory.Delete(basePath, true);
return basePath;
}
} }
} }

View File

@ -3,7 +3,6 @@
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Tournament.IO; using osu.Game.Tournament.IO;
@ -20,7 +19,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
// don't use clean run because files are being written before osu! launches. // don't use clean run because files are being written before osu! launches.
using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation))) using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation)))
{ {
string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(CheckIPCLocation)); string basePath = CustomTourneyDirectoryTest.PrepareBasePath(nameof(CheckIPCLocation));
// Set up a fake IPC client for the IPC Storage to switch to. // Set up a fake IPC client for the IPC Storage to switch to.
string testStableInstallDirectory = Path.Combine(basePath, "stable-ce"); string testStableInstallDirectory = Path.Combine(basePath, "stable-ce");
@ -42,9 +41,16 @@ namespace osu.Game.Tournament.Tests.NonVisual
} }
finally finally
{ {
host.Storage.DeleteDirectory(testStableInstallDirectory);
host.Storage.DeleteDirectory("tournaments");
host.Exit(); host.Exit();
try
{
if (Directory.Exists(basePath))
Directory.Delete(basePath, true);
}
catch
{
}
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tournament.Tests.NonVisual
return tournament; return tournament;
} }
public static void WaitForOrAssert(Func<bool> result, string failureMessage, int timeout = 90000) public static void WaitForOrAssert(Func<bool> result, string failureMessage, int timeout = 30000)
{ {
Task task = Task.Run(() => Task task = Task.Run(() =>
{ {