1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Merge pull request #16194 from peppy/fix-results-screen-wait-test

Fix intermittent test failures on `TestSceneResultsScreen` due to long delay step
This commit is contained in:
Dan Balasescu 2021-12-21 16:56:49 +09:00 committed by GitHub
commit a53c67b2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -203,8 +203,12 @@ namespace osu.Game.Tests.Visual.Ranking
{
DelayedFetchResultsScreen screen = null;
AddStep("load results", () => Child = new TestResultsContainer(screen = new DelayedFetchResultsScreen(TestResources.CreateTestScoreInfo(), 3000)));
var tcs = new TaskCompletionSource();
AddStep("load results", () => Child = new TestResultsContainer(screen = new DelayedFetchResultsScreen(TestResources.CreateTestScoreInfo(), tcs.Task)));
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddStep("click expanded panel", () =>
{
var expandedPanel = this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded);
@ -212,6 +216,10 @@ namespace osu.Game.Tests.Visual.Ranking
InputManager.Click(MouseButton.Left);
});
AddAssert("no fetch yet", () => !screen.FetchCompleted);
AddStep("allow fetch", () => tcs.SetResult());
AddUntilStep("wait for fetch", () => screen.FetchCompleted);
AddAssert("expanded panel still on screen", () => this.ChildrenOfType<ScorePanel>().Single(p => p.State == PanelState.Expanded).ScreenSpaceDrawQuad.TopLeft.X > 0);
}
@ -295,21 +303,21 @@ namespace osu.Game.Tests.Visual.Ranking
private class DelayedFetchResultsScreen : TestResultsScreen
{
private readonly Task fetchWaitTask;
public bool FetchCompleted { get; private set; }
private readonly double delay;
public DelayedFetchResultsScreen(ScoreInfo score, double delay)
public DelayedFetchResultsScreen(ScoreInfo score, Task fetchWaitTask = null)
: base(score)
{
this.delay = delay;
this.fetchWaitTask = fetchWaitTask ?? Task.CompletedTask;
}
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(delay));
await fetchWaitTask;
var scores = new List<ScoreInfo>();