mirror of https://github.com/ppy/osu
Merge pull request #10159 from peppy/fix-test-storage-weirdness
Fix headless test storage misdirection
This commit is contained in:
commit
71f32a2e37
|
@ -22,27 +22,16 @@ namespace osu.Game.Tests.Visual.Collections
|
|||
{
|
||||
public class TestSceneManageCollectionsDialog : OsuManualInputManagerTestScene
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
private readonly Container content;
|
||||
private readonly DialogOverlay dialogOverlay;
|
||||
private readonly CollectionManager manager;
|
||||
private DialogOverlay dialogOverlay;
|
||||
private CollectionManager manager;
|
||||
|
||||
private RulesetStore rulesets;
|
||||
private BeatmapManager beatmapManager;
|
||||
|
||||
private ManageCollectionsDialog dialog;
|
||||
|
||||
public TestSceneManageCollectionsDialog()
|
||||
{
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
manager = new CollectionManager(LocalStorage),
|
||||
content = new Container { RelativeSizeAxes = Axes.Both },
|
||||
dialogOverlay = new DialogOverlay()
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host)
|
||||
{
|
||||
|
@ -50,14 +39,16 @@ private void load(GameHost host)
|
|||
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, host, Beatmap.Default));
|
||||
|
||||
beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
dependencies.Cache(manager);
|
||||
dependencies.Cache(dialogOverlay);
|
||||
return dependencies;
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
manager = new CollectionManager(LocalStorage),
|
||||
Content,
|
||||
dialogOverlay = new DialogOverlay()
|
||||
});
|
||||
|
||||
Dependencies.Cache(manager);
|
||||
Dependencies.Cache(dialogOverlay);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
|
|
@ -34,6 +34,8 @@ public abstract class OsuGameTestScene : OsuManualInputManagerTestScene
|
|||
|
||||
protected TestOsuGame Game;
|
||||
|
||||
protected override bool UseFreshStoragePerRun => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host)
|
||||
{
|
||||
|
|
|
@ -23,25 +23,15 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||
{
|
||||
public class TestSceneFilterControl : OsuManualInputManagerTestScene
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
private readonly CollectionManager collectionManager;
|
||||
private CollectionManager collectionManager;
|
||||
|
||||
private RulesetStore rulesets;
|
||||
private BeatmapManager beatmapManager;
|
||||
|
||||
private FilterControl control;
|
||||
|
||||
public TestSceneFilterControl()
|
||||
{
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
collectionManager = new CollectionManager(LocalStorage),
|
||||
content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host)
|
||||
{
|
||||
|
@ -49,13 +39,14 @@ private void load(GameHost host)
|
|||
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, Audio, host, Beatmap.Default));
|
||||
|
||||
beatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
dependencies.Cache(collectionManager);
|
||||
return dependencies;
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
collectionManager = new CollectionManager(LocalStorage),
|
||||
Content
|
||||
});
|
||||
|
||||
Dependencies.Cache(collectionManager);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class OsuTestScene : TestScene
|
|||
private Lazy<Storage> localStorage;
|
||||
protected Storage LocalStorage => localStorage.Value;
|
||||
|
||||
private readonly Lazy<DatabaseContextFactory> contextFactory;
|
||||
private Lazy<DatabaseContextFactory> contextFactory;
|
||||
|
||||
protected IAPIProvider API
|
||||
{
|
||||
|
@ -71,6 +71,17 @@ protected IAPIProvider API
|
|||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
contextFactory = new Lazy<DatabaseContextFactory>(() =>
|
||||
{
|
||||
var factory = new DatabaseContextFactory(LocalStorage);
|
||||
factory.ResetDatabase();
|
||||
using (var usage = factory.Get())
|
||||
usage.Migrate();
|
||||
return factory;
|
||||
});
|
||||
|
||||
RecycleLocalStorage();
|
||||
|
||||
var baseDependencies = base.CreateChildDependencies(parent);
|
||||
|
||||
var providedRuleset = CreateRuleset();
|
||||
|
@ -104,19 +115,11 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
|
|||
|
||||
protected OsuTestScene()
|
||||
{
|
||||
RecycleLocalStorage();
|
||||
contextFactory = new Lazy<DatabaseContextFactory>(() =>
|
||||
{
|
||||
var factory = new DatabaseContextFactory(LocalStorage);
|
||||
factory.ResetDatabase();
|
||||
using (var usage = factory.Get())
|
||||
usage.Migrate();
|
||||
return factory;
|
||||
});
|
||||
|
||||
base.Content.Add(content = new DrawSizePreservingFillContainer());
|
||||
}
|
||||
|
||||
protected virtual bool UseFreshStoragePerRun => false;
|
||||
|
||||
public virtual void RecycleLocalStorage()
|
||||
{
|
||||
if (localStorage?.IsValueCreated == true)
|
||||
|
@ -131,9 +134,13 @@ public virtual void RecycleLocalStorage()
|
|||
}
|
||||
}
|
||||
|
||||
localStorage = new Lazy<Storage>(() => new NativeStorage(Path.Combine(RuntimeInfo.StartupDirectory, $"{GetType().Name}-{Guid.NewGuid()}")));
|
||||
localStorage =
|
||||
new Lazy<Storage>(() => !UseFreshStoragePerRun && host is HeadlessGameHost ? host.Storage : new NativeStorage(Path.Combine(RuntimeInfo.StartupDirectory, $"{GetType().Name}-{Guid.NewGuid()}")));
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
|
||||
[Resolved]
|
||||
protected AudioManager Audio { get; private set; }
|
||||
|
||||
|
@ -172,7 +179,7 @@ protected override void Dispose(bool isDisposing)
|
|||
if (MusicController?.TrackLoaded == true)
|
||||
MusicController.CurrentTrack.Stop();
|
||||
|
||||
if (contextFactory.IsValueCreated)
|
||||
if (contextFactory?.IsValueCreated == true)
|
||||
contextFactory.Value.ResetDatabase();
|
||||
|
||||
RecycleLocalStorage();
|
||||
|
|
Loading…
Reference in New Issue