mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
Add test coverage of SpectatorPlayer
failing to seek on inopportune frame arrival time
This commit is contained in:
parent
dae5569e36
commit
63998ad9f1
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the same as <see cref="TestSeekToGameplayStartFramesArriveAfterPlayerLoad"/> but with the frames arriving just as <see cref="Player"/> is transitioning into existence.
|
||||||
|
/// </summary>
|
||||||
|
[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]
|
[Test]
|
||||||
public void TestFrameStarvationAndResume()
|
public void TestFrameStarvationAndResume()
|
||||||
{
|
{
|
||||||
@ -319,9 +369,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
private void checkPaused(bool state) =>
|
private void checkPaused(bool state) =>
|
||||||
AddUntilStep($"game is {(state ? "paused" : "playing")}", () => player.ChildrenOfType<DrawableRuleset>().First().IsPaused.Value == state);
|
AddUntilStep($"game is {(state ? "paused" : "playing")}", () => player.ChildrenOfType<DrawableRuleset>().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()
|
private void loadSpectatingScreen()
|
||||||
|
@ -88,7 +88,8 @@ namespace osu.Game.Tests.Visual.Spectator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user to send frames for.</param>
|
/// <param name="userId">The user to send frames for.</param>
|
||||||
/// <param name="count">The total number of frames to send.</param>
|
/// <param name="count">The total number of frames to send.</param>
|
||||||
public void SendFramesFromUser(int userId, int count)
|
/// <param name="startTime">The time to start gameplay frames from.</param>
|
||||||
|
public void SendFramesFromUser(int userId, int count, double startTime = 0)
|
||||||
{
|
{
|
||||||
var frames = new List<LegacyReplayFrame>();
|
var frames = new List<LegacyReplayFrame>();
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ namespace osu.Game.Tests.Visual.Spectator
|
|||||||
flush();
|
flush();
|
||||||
|
|
||||||
var buttonState = currentFrameIndex == lastFrameIndex ? ReplayButtonState.None : ReplayButtonState.Left1;
|
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();
|
flush();
|
||||||
|
Loading…
Reference in New Issue
Block a user