From e33de9b658d9c62bfae35d9e2556d2fc0577eb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 9 Oct 2025 09:46:32 +0200 Subject: [PATCH] Add test demonstrating failure scenario --- .../TestSceneSongSelectNavigation.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/osu.Game.Tests/Visual/Navigation/TestSceneSongSelectNavigation.cs b/osu.Game.Tests/Visual/Navigation/TestSceneSongSelectNavigation.cs index d325ce8b36..f161c4cea0 100644 --- a/osu.Game.Tests/Visual/Navigation/TestSceneSongSelectNavigation.cs +++ b/osu.Game.Tests/Visual/Navigation/TestSceneSongSelectNavigation.cs @@ -10,10 +10,12 @@ using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Leaderboards; using osu.Game.Overlays; using osu.Game.Overlays.Mods; +using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Screens; @@ -24,6 +26,7 @@ using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; using osu.Game.Screens.SelectV2; using osu.Game.Tests.Beatmaps.IO; +using osu.Game.Tests.Resources; using osuTK.Input; namespace osu.Game.Tests.Visual.Navigation @@ -271,6 +274,33 @@ namespace osu.Game.Tests.Visual.Navigation AddUntilStep("selected beatmap is still osu! ruleset", () => Game.Beatmap.Value.BeatmapInfo, () => Is.EqualTo(selectedBeatmap)); } + /// + /// Note: This test was written to demonstrate the failure described at https://github.com/ppy/osu/issues/35023, + /// but because the failure scenario there entailed a race condition, it was possible for the test to pass regardless + /// unless was increased. + /// + [Test] + public void TestPresentFromResults() + { + BeatmapSetInfo beatmapToPresent = null!; + BeatmapSetInfo beatmapToPlay = null!; + AddStep("manually insert beatmap to be presented", () => + { + Game.Realm.Write(r => + { + var beatmapSet = TestResources.CreateTestBeatmapSetInfo(3, [r.Find("osu")]); + r.Add(beatmapSet); + beatmapToPresent = beatmapSet.Detach(); + }); + }); + AddStep("import beatmap", () => beatmapToPlay = BeatmapImportHelper.LoadQuickOszIntoOsu(Game).GetResultSafely()); + AddStep("set global beatmap", () => Game.Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(beatmapToPlay.Beatmaps.First())); + playToResults(); + AddStep("present beatmap from results", () => Game.PresentBeatmap(beatmapToPresent)); + AddUntilStep("back at song select", () => Game.ScreenStack.CurrentScreen is SoloSongSelect); + AddUntilStep("presented beatmap is current", () => Game.Beatmap.Value.BeatmapSetInfo.Equals(beatmapToPresent)); + } + private Func playToResults() { var player = playToCompletion();