1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:25:05 +08:00

Merge pull request #24880 from bdach/flaky-scoreboard-test

Fix `TestFriendScore` intermittently failing due to randomness
This commit is contained in:
Salman Ahmed 2023-09-22 02:09:04 +03:00 committed by GitHub
commit d18bd2d2ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,10 +3,10 @@
#nullable disable #nullable disable
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.PolygonExtensions; using osu.Framework.Extensions.PolygonExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -161,10 +161,16 @@ namespace osu.Game.Tests.Visual.Gameplay
int playerNumber = 1; int playerNumber = 1;
AddRepeatStep("add 3 other players", () => createRandomScore(new APIUser { Username = $"Player {playerNumber++}" }), 3); AddRepeatStep("add 3 other players", () => createRandomScore(new APIUser { Username = $"Player {playerNumber++}" }), 3);
AddUntilStep("there are no pink color score", () => leaderboard.ChildrenOfType<Box>().All(b => b.Colour != Color4Extensions.FromHex("ff549a"))); AddUntilStep("no pink color scores",
() => leaderboard.ChildrenOfType<Box>().Select(b => ((Colour4)b.Colour).ToHex()),
() => Does.Not.Contain("#FF549A"));
AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3); AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3);
AddUntilStep("there are pink color for friend score", () => leaderboard.GetScoreByUsername("my friend").ChildrenOfType<Box>().Any(b => b.Colour == Color4Extensions.FromHex("ff549a"))); AddUntilStep("at least one friend score is pink",
() => leaderboard.GetAllScoresForUsername("my friend")
.SelectMany(score => score.ChildrenOfType<Box>())
.Select(b => ((Colour4)b.Colour).ToHex()),
() => Does.Contain("#FF549A"));
} }
private void addLocalPlayer() private void addLocalPlayer()
@ -208,10 +214,8 @@ namespace osu.Game.Tests.Visual.Gameplay
return scoreItem != null && scoreItem.ScorePosition == expectedPosition; return scoreItem != null && scoreItem.ScorePosition == expectedPosition;
} }
public GameplayLeaderboardScore GetScoreByUsername(string username) public IEnumerable<GameplayLeaderboardScore> GetAllScoresForUsername(string username)
{ => Flow.Where(i => i.User?.Username == username);
return Flow.FirstOrDefault(i => i.User?.Username == username);
}
} }
} }
} }