Skip to content

Commit

Permalink
Merge pull request ppy#16167 from peppy/fix-song-select-test-failure
Browse files Browse the repository at this point in the history
Fix occasional failures in `TestScenePlaySongSelect`
  • Loading branch information
peppy authored Dec 20, 2021
2 parents 6bbc9cc + 0b7daf5 commit 488e1f8
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@ public void TestStartAfterUnMatchingFilterDoesNotStart()
public void TestExternalBeatmapChangeWhileFiltered(bool differentRuleset)
{
createSongSelect();
addManyTestMaps();
// ensure there is at least 1 difficulty for each of the rulesets
// (catch is excluded inside of addManyTestMaps).
addManyTestMaps(3);

changeRuleset(0);

Expand All @@ -488,8 +490,9 @@ public void TestExternalBeatmapChangeWhileFiltered(bool differentRuleset)
AddStep("select beatmap externally", () =>
{
target = manager.GetAllUsableBeatmapSets()
.Where(b => b.Beatmaps.Any(bi => bi.RulesetID == targetRuleset))
.ElementAt(5).Beatmaps.First(bi => bi.RulesetID == targetRuleset);
.First(b => b.Beatmaps.Any(bi => bi.RulesetID == targetRuleset))
.Beatmaps
.First(bi => bi.RulesetID == targetRuleset);

Beatmap.Value = manager.GetWorkingBeatmap(target);
});
Expand Down Expand Up @@ -518,7 +521,9 @@ public void TestExternalBeatmapChangeWhileFiltered(bool differentRuleset)
public void TestExternalBeatmapChangeWhileFilteredThenRefilter()
{
createSongSelect();
addManyTestMaps();
// ensure there is at least 1 difficulty for each of the rulesets
// (catch is excluded inside of addManyTestMaps).
addManyTestMaps(3);

changeRuleset(0);

Expand All @@ -534,8 +539,10 @@ public void TestExternalBeatmapChangeWhileFilteredThenRefilter()

AddStep("select beatmap externally", () =>
{
target = manager.GetAllUsableBeatmapSets().Where(b => b.Beatmaps.Any(bi => bi.RulesetID == 1))
.ElementAt(5).Beatmaps.First();
target = manager
.GetAllUsableBeatmapSets()
.First(b => b.Beatmaps.Any(bi => bi.RulesetID == 1))
.Beatmaps.First();

Beatmap.Value = manager.GetWorkingBeatmap(target);
});
Expand Down Expand Up @@ -877,14 +884,21 @@ private void createSongSelect()
AddUntilStep("wait for carousel loaded", () => songSelect.Carousel.IsAlive);
}

private void addManyTestMaps()
/// <summary>
/// Imports test beatmap sets to show in the carousel.
/// </summary>
/// <param name="difficultyCountPerSet">
/// The exact count of difficulties to create for each beatmap set.
/// A <see langword="null"/> value causes the count of difficulties to be selected randomly.
/// </param>
private void addManyTestMaps(int? difficultyCountPerSet = null)
{
AddStep("import test maps", () =>
{
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();

for (int i = 0; i < 100; i += 10)
manager.Import(TestResources.CreateTestBeatmapSetInfo(rulesets: usableRulesets)).Wait();
for (int i = 0; i < 10; i++)
manager.Import(TestResources.CreateTestBeatmapSetInfo(difficultyCountPerSet, usableRulesets)).Wait();
});
}

Expand Down

0 comments on commit 488e1f8

Please sign in to comment.