Skip to content

Commit

Permalink
Fix intermittent test failures on TestSceneResultsScreen due to lon…
Browse files Browse the repository at this point in the history
…g delay step

Using real time delays of 3 seconds doesn't play well with headless runs.
  • Loading branch information
peppy committed Dec 21, 2021
1 parent a8cd962 commit c0a8758
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,23 @@ public void TestFetchScoresAfterShowingStatistics()
{
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);
InputManager.MoveMouseTo(expandedPanel);
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);
}
Expand Down Expand Up @@ -295,21 +303,21 @@ protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresC

private class DelayedFetchResultsScreen : TestResultsScreen
{
public bool FetchCompleted { get; private set; }
private readonly Task fetchWaitTask;

private readonly double delay;
public bool FetchCompleted { get; private set; }

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>();

Expand Down

0 comments on commit c0a8758

Please sign in to comment.