mirror of
https://github.com/ppy/osu
synced 2025-01-03 04:42:10 +00:00
Ensure request handling for OnlinePlayTestScene
runs in a scheduled fashion
This commit is contained in:
parent
c18dd8c8fb
commit
f935f034c2
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -67,7 +68,24 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
// 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 => handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
|
||||
((DummyAPIAccess)API).HandleRequest = request =>
|
||||
{
|
||||
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
// Because some of the handlers use realm, we need to ensure the game is still alive when firing.
|
||||
// If we don't, a stray `PerformAsync` could hit an `ObjectDisposedException` if running too late.
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
bool result = handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
|
||||
tcs.SetResult(result);
|
||||
}, false);
|
||||
|
||||
#pragma warning disable RS0030
|
||||
// We can't GetResultSafely() here (will fail with "Can't use GetResultSafely from inside an async operation."), but Wait is safe enough due to
|
||||
// the task being a TaskCompletionSource.
|
||||
return tcs.Task.Result;
|
||||
#pragma warning restore RS0030
|
||||
};
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user