From 5631e75f16073892a81b1c4e6af5959049ee2b0c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Nov 2021 14:11:27 +0900 Subject: [PATCH] Restructure how the headless storage is used / documented to hopefully make more sense --- osu.Game/Tests/Visual/OsuTestScene.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 2bacfcebca..cb4af67839 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -81,8 +81,7 @@ namespace osu.Game.Tests.Visual protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { - if (!UseFreshStoragePerRun) - isolatedHostStorage = (parent.Get() as HeadlessGameHost)?.Storage; + isolatedHostStorage = (parent.Get() as HeadlessGameHost)?.Storage; Resources = parent.Get().Resources; @@ -149,8 +148,16 @@ namespace osu.Game.Tests.Visual } } - localStorage = - new Lazy(() => isolatedHostStorage ?? new TemporaryNativeStorage($"{GetType().Name}-{Guid.NewGuid()}")); + localStorage = new Lazy(() => + { + // When running headless, there is an opportunity to use the host storage rather than creating a second isolated one. + // This is because the host is recycled per TestScene execution in headless at an nunit level. + // Importantly, we can't use this optimisation when `UseFreshStoragePerRun` is true, as it doesn't reset per test method. + if (!UseFreshStoragePerRun && isolatedHostStorage != null) + return isolatedHostStorage; + + return new TemporaryNativeStorage($"{GetType().Name}-{Guid.NewGuid()}"); + }); } [Resolved]