From 8cdad5f4d9448613650ffc803ed50e39a895c066 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 20:15:10 +0900 Subject: [PATCH 1/6] Remove incorrectly used `gameSuffix` from `CleanRunHeadlessGameHost` --- osu.Game/Tests/CleanRunHeadlessGameHost.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Tests/CleanRunHeadlessGameHost.cs b/osu.Game/Tests/CleanRunHeadlessGameHost.cs index 7d7f011f6a..1c341ea243 100644 --- a/osu.Game/Tests/CleanRunHeadlessGameHost.cs +++ b/osu.Game/Tests/CleanRunHeadlessGameHost.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Runtime.CompilerServices; using osu.Framework.Testing; @@ -14,13 +15,12 @@ namespace osu.Game.Tests /// /// Create a new instance. /// - /// An optional suffix which will isolate this host from others called from the same method source. /// Whether to bind IPC channels. /// Whether the host should be forced to run in realtime, rather than accelerated test time. /// Whether to bypass directory cleanup on host disposal. Should be used only if a subsequent test relies on the files still existing. /// The name of the calling method, used for test file isolation and clean-up. - public CleanRunHeadlessGameHost(string gameSuffix = @"", bool bindIPC = false, bool realtime = true, bool bypassCleanup = false, [CallerMemberName] string callingMethodName = @"") - : base(callingMethodName + gameSuffix, bindIPC, realtime, bypassCleanup: bypassCleanup) + public CleanRunHeadlessGameHost(bool bindIPC = false, bool realtime = true, bool bypassCleanup = false, [CallerMemberName] string callingMethodName = @"") + : base($"{callingMethodName}-{Guid.NewGuid()}", bindIPC, realtime, bypassCleanup: bypassCleanup) { } From 4b88e257e57cdf76d8da3cc880871f691cf208a6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 20:17:20 +0900 Subject: [PATCH 2/6] Update usages of `CleanRunHeadlessGameHost` to match new signature --- .../Beatmaps/IO/ImportBeatmapTest.cs | 50 +++++++++---------- osu.Game.Tests/Database/RealmTest.cs | 4 +- .../NonVisual/CustomDataDirectoryTest.cs | 2 +- osu.Game.Tests/Skins/IO/ImportSkinTest.cs | 2 +- .../NonVisual/CustomTourneyDirectoryTest.cs | 2 +- .../NonVisual/DataLoadTest.cs | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs index 6d0d5702e9..9f3709f7a3 100644 --- a/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs +++ b/osu.Game.Tests/Beatmaps/IO/ImportBeatmapTest.cs @@ -40,7 +40,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportWhenClosed() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -57,7 +57,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportThenDelete() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -78,7 +78,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportThenDeleteFromStream() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -114,7 +114,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportThenImport() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -140,7 +140,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportThenImportWithReZip() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -192,7 +192,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportThenImportWithChangedHashedFile() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -247,7 +247,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Ignore("intentionally broken by import optimisations")] public async Task TestImportThenImportWithChangedFile() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -298,7 +298,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportThenImportWithDifferentFilename() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -351,7 +351,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportCorruptThenImport() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -392,7 +392,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestModelCreationFailureDoesntReturn() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -428,7 +428,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestRollbackOnFailure() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -507,7 +507,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportThenDeleteThenImport() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -534,7 +534,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportThenDeleteThenImportWithOnlineIDsMissing() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost($"{nameof(ImportBeatmapTest)}")) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -566,7 +566,7 @@ namespace osu.Game.Tests.Beatmaps.IO public async Task TestImportWithDuplicateBeatmapIDs() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -621,8 +621,8 @@ namespace osu.Game.Tests.Beatmaps.IO [NonParallelizable] public void TestImportOverIPC() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost($"{nameof(ImportBeatmapTest)}-host", true)) - using (HeadlessGameHost client = new CleanRunHeadlessGameHost($"{nameof(ImportBeatmapTest)}-client", true)) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost(true)) + using (HeadlessGameHost client = new CleanRunHeadlessGameHost(true)) { try { @@ -651,7 +651,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportWhenFileOpen() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -673,7 +673,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportWithDuplicateHashes() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -715,7 +715,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportNestedStructure() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -760,7 +760,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestImportWithIgnoredDirectoryInArchive() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -814,7 +814,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestUpdateBeatmapInfo() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -844,7 +844,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public async Task TestUpdateBeatmapFile() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -888,7 +888,7 @@ namespace osu.Game.Tests.Beatmaps.IO public void TestSaveRemovesInvalidCharactersFromPath() { // unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -922,7 +922,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public void TestCreateNewEmptyBeatmap() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { @@ -949,7 +949,7 @@ namespace osu.Game.Tests.Beatmaps.IO [Test] public void TestCreateNewBeatmapWithObject() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { diff --git a/osu.Game.Tests/Database/RealmTest.cs b/osu.Game.Tests/Database/RealmTest.cs index 6904464485..4e67f09dca 100644 --- a/osu.Game.Tests/Database/RealmTest.cs +++ b/osu.Game.Tests/Database/RealmTest.cs @@ -30,7 +30,7 @@ namespace osu.Game.Tests.Database protected void RunTestWithRealm(Action testAction, [CallerMemberName] string caller = "") { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(caller)) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller)) { host.Run(new RealmTestGame(() => { @@ -54,7 +54,7 @@ namespace osu.Game.Tests.Database protected void RunTestWithRealmAsync(Func testAction, [CallerMemberName] string caller = "") { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(caller)) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller)) { host.Run(new RealmTestGame(async () => { diff --git a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs index 8d15be44fa..999994cae0 100644 --- a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs +++ b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs @@ -315,7 +315,7 @@ namespace osu.Game.Tests.NonVisual public CustomTestHeadlessGameHost([CallerMemberName] string callingMethodName = @"") : base(callingMethodName: callingMethodName) { - string defaultStorageLocation = getDefaultLocationFor(callingMethodName); + string defaultStorageLocation = getDefaultLocationFor(Name); InitialStorage = new DesktopStorage(defaultStorageLocation, this); InitialStorage.DeleteDirectory(string.Empty); diff --git a/osu.Game.Tests/Skins/IO/ImportSkinTest.cs b/osu.Game.Tests/Skins/IO/ImportSkinTest.cs index f2ce002650..40d2455106 100644 --- a/osu.Game.Tests/Skins/IO/ImportSkinTest.cs +++ b/osu.Game.Tests/Skins/IO/ImportSkinTest.cs @@ -319,7 +319,7 @@ namespace osu.Game.Tests.Skins.IO private async Task runSkinTest(Func action, [CallerMemberName] string callingMethodName = @"") { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName)) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: callingMethodName)) { try { diff --git a/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs b/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs index 3619aae7e0..14cab63348 100644 --- a/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs +++ b/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs @@ -17,7 +17,7 @@ namespace osu.Game.Tournament.Tests.NonVisual [Test] public void TestDefaultDirectory() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestDefaultDirectory))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { diff --git a/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs b/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs index 692cb3870c..db019f9242 100644 --- a/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs +++ b/osu.Game.Tournament.Tests/NonVisual/DataLoadTest.cs @@ -15,7 +15,7 @@ namespace osu.Game.Tournament.Tests.NonVisual [Test] public void TestUnavailableRuleset() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestUnavailableRuleset))) + using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { From be02c3f9f8bb8078913afb34342d753ce7f475c5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 20:17:47 +0900 Subject: [PATCH 3/6] Fix a couple of remaining cases of tests not using the new temporary file location for storage --- .../NonVisual/CustomTourneyDirectoryTest.cs | 40 +++---------------- .../NonVisual/IPCLocationTest.cs | 15 ++----- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs b/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs index 14cab63348..fc5d3b652f 100644 --- a/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs +++ b/osu.Game.Tournament.Tests/NonVisual/CustomTourneyDirectoryTest.cs @@ -2,10 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System.IO; +using System.Linq; using NUnit.Framework; -using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Platform; +using osu.Framework.Testing; using osu.Game.Tests; using osu.Game.Tournament.Configuration; @@ -36,9 +37,9 @@ namespace osu.Game.Tournament.Tests.NonVisual [Test] public void TestCustomDirectory() { - using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file. + using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file. { - string osuDesktopStorage = PrepareBasePath(nameof(TestCustomDirectory)); + string osuDesktopStorage = Path.Combine(host.UserStoragePaths.First(), nameof(TestCustomDirectory)); const string custom_tournament = "custom"; // need access before the game has constructed its own storage yet. @@ -60,15 +61,6 @@ namespace osu.Game.Tournament.Tests.NonVisual finally { host.Exit(); - - try - { - if (Directory.Exists(osuDesktopStorage)) - Directory.Delete(osuDesktopStorage, true); - } - catch - { - } } } } @@ -76,9 +68,9 @@ namespace osu.Game.Tournament.Tests.NonVisual [Test] public void TestMigration() { - using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration. + using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration. { - string osuRoot = PrepareBasePath(nameof(TestMigration)); + string osuRoot = Path.Combine(host.UserStoragePaths.First(), nameof(TestMigration)); string configFile = Path.Combine(osuRoot, "tournament.ini"); if (File.Exists(configFile)) @@ -146,28 +138,8 @@ namespace osu.Game.Tournament.Tests.NonVisual finally { host.Exit(); - - try - { - if (Directory.Exists(osuRoot)) - Directory.Delete(osuRoot, true); - } - catch - { - } } } } - - 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; - } } } diff --git a/osu.Game.Tournament.Tests/NonVisual/IPCLocationTest.cs b/osu.Game.Tournament.Tests/NonVisual/IPCLocationTest.cs index db89855db7..952eb72bf4 100644 --- a/osu.Game.Tournament.Tests/NonVisual/IPCLocationTest.cs +++ b/osu.Game.Tournament.Tests/NonVisual/IPCLocationTest.cs @@ -2,9 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System.IO; +using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Platform; +using osu.Framework.Testing; using osu.Game.Tournament.IO; using osu.Game.Tournament.IPC; @@ -17,9 +19,9 @@ namespace osu.Game.Tournament.Tests.NonVisual public void CheckIPCLocation() { // don't use clean run because files are being written before osu! launches. - using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation))) + using (var host = new TestRunHeadlessGameHost(nameof(CheckIPCLocation))) { - string basePath = CustomTourneyDirectoryTest.PrepareBasePath(nameof(CheckIPCLocation)); + string basePath = Path.Combine(host.UserStoragePaths.First(), nameof(CheckIPCLocation)); // Set up a fake IPC client for the IPC Storage to switch to. string testStableInstallDirectory = Path.Combine(basePath, "stable-ce"); @@ -42,15 +44,6 @@ namespace osu.Game.Tournament.Tests.NonVisual finally { host.Exit(); - - try - { - if (Directory.Exists(basePath)) - Directory.Delete(basePath, true); - } - catch - { - } } } } From 1c0dc204c4f01b3c634c6319a336b1df79d3c915 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 20:24:37 +0900 Subject: [PATCH 4/6] Fix some regressing behaviour due to `CleanRunHeadlessGameHost`'s naming structure changing --- osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs | 8 ++++++-- osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs | 10 +++++----- osu.Game/Tests/CleanRunHeadlessGameHost.cs | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs index 686e053246..d4ec5e897b 100644 --- a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs +++ b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs @@ -128,8 +128,12 @@ namespace osu.Game.Tests.Collections.IO [Test] public async Task TestSaveAndReload() { - using (HeadlessGameHost host = new CleanRunHeadlessGameHost(bypassCleanup: true)) + string firstRunName; + + using (var host = new CleanRunHeadlessGameHost(bypassCleanup: true)) { + firstRunName = host.Name; + try { var osu = LoadOsuIntoHost(host, true); @@ -150,7 +154,7 @@ namespace osu.Game.Tests.Collections.IO } // Name matches the automatically chosen name from `CleanRunHeadlessGameHost` above, so we end up using the same storage location. - using (HeadlessGameHost host = new TestRunHeadlessGameHost(nameof(TestSaveAndReload))) + using (HeadlessGameHost host = new TestRunHeadlessGameHost(firstRunName)) { try { diff --git a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs index 999994cae0..4bb54f1625 100644 --- a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs +++ b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs @@ -25,7 +25,7 @@ namespace osu.Game.Tests.NonVisual { try { - string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory)); + string defaultStorageLocation = getDefaultLocationFor(host); var osu = LoadOsuIntoHost(host); var storage = osu.Dependencies.Get(); @@ -109,7 +109,7 @@ namespace osu.Game.Tests.NonVisual { try { - string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration)); + string defaultStorageLocation = getDefaultLocationFor(host); var osu = LoadOsuIntoHost(host); var storage = osu.Dependencies.Get(); @@ -284,9 +284,9 @@ namespace osu.Game.Tests.NonVisual } } - private static string getDefaultLocationFor(string testTypeName) + private static string getDefaultLocationFor(CustomTestHeadlessGameHost host) { - string path = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, testTypeName); + string path = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, host.Name); if (Directory.Exists(path)) Directory.Delete(path, true); @@ -315,7 +315,7 @@ namespace osu.Game.Tests.NonVisual public CustomTestHeadlessGameHost([CallerMemberName] string callingMethodName = @"") : base(callingMethodName: callingMethodName) { - string defaultStorageLocation = getDefaultLocationFor(Name); + string defaultStorageLocation = getDefaultLocationFor(this); InitialStorage = new DesktopStorage(defaultStorageLocation, this); InitialStorage.DeleteDirectory(string.Empty); diff --git a/osu.Game/Tests/CleanRunHeadlessGameHost.cs b/osu.Game/Tests/CleanRunHeadlessGameHost.cs index 1c341ea243..2be2f3cd65 100644 --- a/osu.Game/Tests/CleanRunHeadlessGameHost.cs +++ b/osu.Game/Tests/CleanRunHeadlessGameHost.cs @@ -12,6 +12,8 @@ namespace osu.Game.Tests /// public class CleanRunHeadlessGameHost : TestRunHeadlessGameHost { + public new string Name => base.Name; + /// /// Create a new instance. /// From a9a7a339741104ace46f6f4af009e3a4dda91ea1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 25 Dec 2021 02:03:58 +0900 Subject: [PATCH 5/6] Update framework --- osu.Android.props | 2 +- osu.Game/Tests/CleanRunHeadlessGameHost.cs | 2 -- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 4f0125bed2..31a3bc8c45 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game/Tests/CleanRunHeadlessGameHost.cs b/osu.Game/Tests/CleanRunHeadlessGameHost.cs index 2be2f3cd65..1c341ea243 100644 --- a/osu.Game/Tests/CleanRunHeadlessGameHost.cs +++ b/osu.Game/Tests/CleanRunHeadlessGameHost.cs @@ -12,8 +12,6 @@ namespace osu.Game.Tests /// public class CleanRunHeadlessGameHost : TestRunHeadlessGameHost { - public new string Name => base.Name; - /// /// Create a new instance. /// diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 565f78e2d4..2c97bae360 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index bdb3b0b149..de084c0297 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -60,7 +60,7 @@ - + @@ -83,7 +83,7 @@ - + From 7088471cad90a50998b594c48049ae0920cbe608 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 23:55:08 +0900 Subject: [PATCH 6/6] Protect against test failures due to logger being set too early (and beginning logging) --- osu.Game/Tests/CleanRunHeadlessGameHost.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Tests/CleanRunHeadlessGameHost.cs b/osu.Game/Tests/CleanRunHeadlessGameHost.cs index 1c341ea243..754c9044e8 100644 --- a/osu.Game/Tests/CleanRunHeadlessGameHost.cs +++ b/osu.Game/Tests/CleanRunHeadlessGameHost.cs @@ -26,7 +26,14 @@ namespace osu.Game.Tests protected override void SetupForRun() { - Storage.DeleteDirectory(string.Empty); + try + { + Storage.DeleteDirectory(string.Empty); + } + catch + { + // May fail if a logging target has already been set via OsuStorage.ChangeTargetStorage. + } // base call needs to be run *after* storage is emptied, as it updates the (static) logger's storage and may start writing // log entries from another source if a unit test host is shared over multiple tests, causing a file access denied exception.