mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Fix PlaylistResults tests performing delays in real-time when headless
This commit is contained in:
parent
c99e152fe4
commit
adf2dc36c9
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
AddStep("bind user score info handler", () =>
|
AddStep("bind user score info handler", () =>
|
||||||
{
|
{
|
||||||
userScore = new TestScoreInfo(new OsuRuleset().RulesetInfo) { OnlineScoreID = currentScoreId++ };
|
userScore = new TestScoreInfo(new OsuRuleset().RulesetInfo) { OnlineScoreID = currentScoreId++ };
|
||||||
bindHandler(3000, userScore);
|
bindHandler(true, userScore);
|
||||||
});
|
});
|
||||||
|
|
||||||
createResults(() => userScore);
|
createResults(() => userScore);
|
||||||
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestShowNullUserScoreWithDelay()
|
public void TestShowNullUserScoreWithDelay()
|
||||||
{
|
{
|
||||||
AddStep("bind delayed handler", () => bindHandler(3000));
|
AddStep("bind delayed handler", () => bindHandler(true));
|
||||||
|
|
||||||
createResults();
|
createResults();
|
||||||
waitForDisplay();
|
waitForDisplay();
|
||||||
@ -103,7 +103,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
createResults();
|
createResults();
|
||||||
waitForDisplay();
|
waitForDisplay();
|
||||||
|
|
||||||
AddStep("bind delayed handler", () => bindHandler(3000));
|
AddStep("bind delayed handler", () => bindHandler(true));
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
createResults(() => userScore);
|
createResults(() => userScore);
|
||||||
waitForDisplay();
|
waitForDisplay();
|
||||||
|
|
||||||
AddStep("bind delayed handler", () => bindHandler(3000));
|
AddStep("bind delayed handler", () => bindHandler(true));
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
@ -169,13 +169,17 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
AddWaitStep("wait for display", 5);
|
AddWaitStep("wait for display", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindHandler(double delay = 0, ScoreInfo userScore = null, bool failRequests = false) => ((DummyAPIAccess)API).HandleRequest = request =>
|
private void bindHandler(bool delayed = false, ScoreInfo userScore = null, bool failRequests = false) => ((DummyAPIAccess)API).HandleRequest = request =>
|
||||||
{
|
{
|
||||||
requestComplete = false;
|
requestComplete = false;
|
||||||
|
|
||||||
|
double delay = delayed ? 3000 : 0;
|
||||||
|
|
||||||
|
Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
if (failRequests)
|
if (failRequests)
|
||||||
{
|
{
|
||||||
triggerFail(request, delay);
|
triggerFail(request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,57 +187,30 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
{
|
{
|
||||||
case ShowPlaylistUserScoreRequest s:
|
case ShowPlaylistUserScoreRequest s:
|
||||||
if (userScore == null)
|
if (userScore == null)
|
||||||
triggerFail(s, delay);
|
triggerFail(s);
|
||||||
else
|
else
|
||||||
triggerSuccess(s, createUserResponse(userScore), delay);
|
triggerSuccess(s, createUserResponse(userScore));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IndexPlaylistScoresRequest i:
|
case IndexPlaylistScoresRequest i:
|
||||||
triggerSuccess(i, createIndexResponse(i), delay);
|
triggerSuccess(i, createIndexResponse(i));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}, delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
private void triggerSuccess<T>(APIRequest<T> req, T result, double delay)
|
private void triggerSuccess<T>(APIRequest<T> req, T result)
|
||||||
where T : class
|
where T : class
|
||||||
{
|
|
||||||
if (delay == 0)
|
|
||||||
success();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await Task.Delay(TimeSpan.FromMilliseconds(delay));
|
|
||||||
Schedule(success);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void success()
|
|
||||||
{
|
{
|
||||||
requestComplete = true;
|
requestComplete = true;
|
||||||
req.TriggerSuccess(result);
|
req.TriggerSuccess(result);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void triggerFail(APIRequest req, double delay)
|
private void triggerFail(APIRequest req)
|
||||||
{
|
|
||||||
if (delay == 0)
|
|
||||||
fail();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await Task.Delay(TimeSpan.FromMilliseconds(delay));
|
|
||||||
Schedule(fail);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void fail()
|
|
||||||
{
|
{
|
||||||
requestComplete = true;
|
requestComplete = true;
|
||||||
req.TriggerFailure(new WebException("Failed."));
|
req.TriggerFailure(new WebException("Failed."));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private MultiplayerScore createUserResponse([NotNull] ScoreInfo userScore)
|
private MultiplayerScore createUserResponse([NotNull] ScoreInfo userScore)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user