From e45d45632421c1091a93428b824f65f06a943cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 21 Sep 2023 21:09:24 +0200 Subject: [PATCH] Fix `TestFriendScore` intermittently failing due to randomness If `createRandomScore()` happened to randomly pick the highest total score when called with `friend` as the sole argument, that particular score would not be pink. `GetScoreByUsername()` would arbitrarily pick the first score for the user, so in this particular case where a friend had the number 1 score, the test would wrongly fail. Fix by checking whether any of the 3 added friend scores have received the pink colour. Because there is more than 1 friend score in the test, doing so ensures that at least one of those should eventually become pink (because, obviously, you can't have two scores at number 1). --- .../Visual/Gameplay/TestSceneGameplayLeaderboard.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs index df1d56c94d..193e8b2571 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayLeaderboard.cs @@ -3,6 +3,7 @@ #nullable disable +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Bindables; @@ -165,8 +166,10 @@ namespace osu.Game.Tests.Visual.Gameplay () => Does.Not.Contain("#FF549A")); AddRepeatStep("add 3 friend score", () => createRandomScore(friend), 3); - AddUntilStep("friend score is pink", - () => leaderboard.GetScoreByUsername("my friend").ChildrenOfType().Select(b => ((Colour4)b.Colour).ToHex()), + AddUntilStep("at least one friend score is pink", + () => leaderboard.GetAllScoresForUsername("my friend") + .SelectMany(score => score.ChildrenOfType()) + .Select(b => ((Colour4)b.Colour).ToHex()), () => Does.Contain("#FF549A")); } @@ -211,10 +214,8 @@ namespace osu.Game.Tests.Visual.Gameplay return scoreItem != null && scoreItem.ScorePosition == expectedPosition; } - public GameplayLeaderboardScore GetScoreByUsername(string username) - { - return Flow.FirstOrDefault(i => i.User?.Username == username); - } + public IEnumerable GetAllScoresForUsername(string username) + => Flow.Where(i => i.User?.Username == username); } } }