diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs
index d614815316..8b420cebc8 100644
--- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs
+++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs
@@ -70,6 +70,56 @@ namespace osu.Game.Tests.Visual.Gameplay
});
}
+ [Test]
+ public void TestSeekToGameplayStartFramesArriveAfterPlayerLoad()
+ {
+ const double gameplay_start = 10000;
+
+ loadSpectatingScreen();
+
+ start();
+
+ waitForPlayer();
+
+ sendFrames(startTime: gameplay_start);
+
+ AddAssert("time is greater than seek target", () => currentFrameStableTime > gameplay_start);
+ }
+
+ ///
+ /// Tests the same as but with the frames arriving just as is transitioning into existence.
+ ///
+ [Test]
+ public void TestSeekToGameplayStartFramesArriveAsPlayerLoaded()
+ {
+ const double gameplay_start = 10000;
+
+ loadSpectatingScreen();
+
+ start();
+
+ AddUntilStep("wait for player loader", () => (Stack.CurrentScreen as PlayerLoader)?.IsLoaded == true);
+
+ AddUntilStep("queue send frames on player load", () =>
+ {
+ var loadingPlayer = (Stack.CurrentScreen as PlayerLoader)?.CurrentPlayer;
+
+ if (loadingPlayer == null)
+ return false;
+
+ loadingPlayer.OnLoadComplete += _ =>
+ {
+ spectatorClient.SendFramesFromUser(streamingUser.Id, 10, gameplay_start);
+ };
+ return true;
+ });
+
+ waitForPlayer();
+
+ AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
+ AddAssert("time is greater than seek target", () => currentFrameStableTime > gameplay_start);
+ }
+
[Test]
public void TestFrameStarvationAndResume()
{
@@ -319,9 +369,9 @@ namespace osu.Game.Tests.Visual.Gameplay
private void checkPaused(bool state) =>
AddUntilStep($"game is {(state ? "paused" : "playing")}", () => player.ChildrenOfType().First().IsPaused.Value == state);
- private void sendFrames(int count = 10)
+ private void sendFrames(int count = 10, double startTime = 0)
{
- AddStep("send frames", () => spectatorClient.SendFramesFromUser(streamingUser.Id, count));
+ AddStep("send frames", () => spectatorClient.SendFramesFromUser(streamingUser.Id, count, startTime));
}
private void loadSpectatingScreen()
diff --git a/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs b/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs
index f5da95bd7b..ac7cb43e02 100644
--- a/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs
+++ b/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs
@@ -88,7 +88,8 @@ namespace osu.Game.Tests.Visual.Spectator
///
/// The user to send frames for.
/// The total number of frames to send.
- public void SendFramesFromUser(int userId, int count)
+ /// The time to start gameplay frames from.
+ public void SendFramesFromUser(int userId, int count, double startTime = 0)
{
var frames = new List();
@@ -102,7 +103,7 @@ namespace osu.Game.Tests.Visual.Spectator
flush();
var buttonState = currentFrameIndex == lastFrameIndex ? ReplayButtonState.None : ReplayButtonState.Left1;
- frames.Add(new LegacyReplayFrame(currentFrameIndex * 100, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
+ frames.Add(new LegacyReplayFrame(currentFrameIndex * 100 + startTime, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
}
flush();