mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Fix potential test failures due to Setup/SetUpSteps ordering
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -56,39 +55,43 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
// Reset the room dependencies to a fresh state.
|
||||
drawableDependenciesContainer.Clear();
|
||||
dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies();
|
||||
drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents);
|
||||
base.SetUpSteps();
|
||||
|
||||
var handler = OnlinePlayDependencies.RequestsHandler;
|
||||
|
||||
// Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead.
|
||||
// To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead.
|
||||
var beatmapManager = dependencies.Get<BeatmapManager>();
|
||||
|
||||
((DummyAPIAccess)API).HandleRequest = request =>
|
||||
AddStep("setup dependencies", () =>
|
||||
{
|
||||
try
|
||||
// Reset the room dependencies to a fresh state.
|
||||
drawableDependenciesContainer.Clear();
|
||||
dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies();
|
||||
drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents);
|
||||
|
||||
var handler = OnlinePlayDependencies.RequestsHandler;
|
||||
|
||||
// Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead.
|
||||
// To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead.
|
||||
var beatmapManager = dependencies.Get<BeatmapManager>();
|
||||
|
||||
((DummyAPIAccess)API).HandleRequest = request =>
|
||||
{
|
||||
return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// These requests can be fired asynchronously, but potentially arrive after game components
|
||||
// have been disposed (ie. realm in BeatmapManager).
|
||||
// This only happens in tests and it's easiest to ignore them for now.
|
||||
Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
try
|
||||
{
|
||||
return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// These requests can be fired asynchronously, but potentially arrive after game components
|
||||
// have been disposed (ie. realm in BeatmapManager).
|
||||
// This only happens in tests and it's easiest to ignore them for now.
|
||||
Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the room dependencies. Called every <see cref="Setup"/>.
|
||||
/// Creates the room dependencies. Called every <see cref="SetUpSteps"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Any custom dependencies required for online play sub-classes should be added here.
|
||||
|
Reference in New Issue
Block a user