From 88ec0cdbc704e041bd6b77ff24d1a4206d888896 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 12 Mar 2024 17:35:00 +0800 Subject: [PATCH] Fix seek ending too early in sample playback test --- .../TestSceneGameplaySamplePlayback.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySamplePlayback.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySamplePlayback.cs index 057197e819..ad3fe7cb7e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySamplePlayback.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneGameplaySamplePlayback.cs @@ -18,6 +18,8 @@ namespace osu.Game.Tests.Visual.Gameplay { protected override bool AllowBackwardsSeeks => true; + private bool seek; + [Test] public void TestAllSamplesStopDuringSeek() { @@ -42,7 +44,7 @@ namespace osu.Game.Tests.Visual.Gameplay if (!samples.Any(s => s.Playing)) return false; - Player.ChildrenOfType().First().Seek(40000); + seek = true; return true; }); @@ -55,10 +57,27 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("sample playback still disabled", () => sampleDisabler.SamplePlaybackDisabled.Value); + AddStep("stop seeking", () => seek = false); + AddUntilStep("seek finished, sample playback enabled", () => !sampleDisabler.SamplePlaybackDisabled.Value); AddUntilStep("any sample is playing", () => Player.ChildrenOfType().Any(s => s.IsPlaying)); } + protected override void Update() + { + base.Update(); + + if (seek) + { + // Frame stable playback is too fast to catch up these days. + // + // We want to keep seeking while asserting various test conditions, so + // continue to seek until we unset the flag. + var gameplayClockContainer = Player.ChildrenOfType().First(); + gameplayClockContainer.Seek(gameplayClockContainer.CurrentTime > 30000 ? 0 : 60000); + } + } + private IEnumerable allSounds => Player.ChildrenOfType(); private IEnumerable allLoopingSounds => allSounds.Where(sound => sound.Looping);