mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:33:01 +08:00
Add extra test coverage and handle case where still at loading screen
This commit is contained in:
parent
d3a55d83c0
commit
7ceb49fbc0
@ -81,7 +81,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
sendFrames(startTime: gameplay_start);
|
||||
|
||||
@ -115,7 +115,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
return true;
|
||||
});
|
||||
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
AddAssert("time is greater than seek target", () => currentFrameStableTime, () => Is.GreaterThan(gameplay_start));
|
||||
@ -129,7 +129,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddAssert("screen hasn't changed", () => Stack.CurrentScreen is SoloSpectatorScreen);
|
||||
|
||||
start();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
sendFrames();
|
||||
AddAssert("ensure frames arrived", () => replayHandler.HasFrames);
|
||||
@ -155,7 +155,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
loadSpectatingScreen();
|
||||
|
||||
start();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
checkPaused(true);
|
||||
|
||||
// send enough frames to ensure play won't be paused
|
||||
@ -171,7 +171,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
sendFrames(300);
|
||||
|
||||
loadSpectatingScreen();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
sendFrames(300);
|
||||
|
||||
@ -186,7 +186,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
start();
|
||||
sendFrames();
|
||||
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
Player lastPlayer = null;
|
||||
AddStep("store first player", () => lastPlayer = player);
|
||||
@ -194,7 +194,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
start();
|
||||
sendFrames();
|
||||
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
AddAssert("player is different", () => lastPlayer != player);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
checkPaused(true);
|
||||
sendFrames();
|
||||
|
||||
@ -223,7 +223,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddStep("stop spectating", () => (Stack.CurrentScreen as Player)?.Exit());
|
||||
AddUntilStep("spectating stopped", () => spectatorScreen.GetChildScreen() == null);
|
||||
@ -236,14 +236,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddStep("stop spectating", () => (Stack.CurrentScreen as Player)?.Exit());
|
||||
AddUntilStep("spectating stopped", () => spectatorScreen.GetChildScreen() == null);
|
||||
|
||||
// host starts playing a new session
|
||||
start();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -298,7 +298,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
}
|
||||
|
||||
@ -309,14 +309,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddStep("send passed", () => spectatorClient.SendEndPlay(streamingUser.Id, SpectatedUserState.Passed));
|
||||
AddUntilStep("state is passed", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Passed);
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddStep("send quit", () => spectatorClient.SendEndPlay(streamingUser.Id));
|
||||
AddUntilStep("state is quit", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Quit);
|
||||
@ -336,18 +336,19 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFailedState()
|
||||
public void TestFailedStateDuringPlay()
|
||||
{
|
||||
loadSpectatingScreen();
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
|
||||
waitForPlayerCurrent();
|
||||
|
||||
AddStep("send failed", () => spectatorClient.SendEndPlay(streamingUser.Id, SpectatedUserState.Failed));
|
||||
AddUntilStep("state is failed", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Failed);
|
||||
@ -356,7 +357,28 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayer();
|
||||
waitForPlayerCurrent();
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFailedStateDuringLoading()
|
||||
{
|
||||
loadSpectatingScreen();
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
|
||||
waitForPlayerLoader();
|
||||
|
||||
AddStep("send failed", () => spectatorClient.SendEndPlay(streamingUser.Id, SpectatedUserState.Failed));
|
||||
AddUntilStep("state is failed", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Failed);
|
||||
|
||||
AddAssert("wait for player exit", () => Stack.CurrentScreen is SoloSpectatorScreen);
|
||||
|
||||
start();
|
||||
sendFrames();
|
||||
waitForPlayerCurrent();
|
||||
AddUntilStep("state is playing", () => spectatorClient.WatchedUserStates[streamingUser.Id].State == SpectatedUserState.Playing);
|
||||
}
|
||||
|
||||
@ -368,7 +390,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
private double currentFrameStableTime
|
||||
=> player.ChildrenOfType<FrameStabilityContainer>().First().CurrentTime;
|
||||
|
||||
private void waitForPlayer() => AddUntilStep("wait for player", () => this.ChildrenOfType<Player>().SingleOrDefault()?.IsLoaded == true);
|
||||
private void waitForPlayerLoader() => AddUntilStep("wait for loading", () => this.ChildrenOfType<SpectatorPlayerLoader>().SingleOrDefault()?.IsLoaded == true);
|
||||
|
||||
private void waitForPlayerCurrent() => AddUntilStep("wait for player current", () => this.ChildrenOfType<Player>().SingleOrDefault()?.IsCurrentScreen() == true);
|
||||
|
||||
private void start(int? beatmapId = null) => AddStep("start play", () => spectatorClient.SendStartPlay(streamingUser.Id, beatmapId ?? importedBeatmapId));
|
||||
|
||||
|
@ -180,31 +180,32 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override void FailGameplay(int userId)
|
||||
{
|
||||
if (this.GetChildScreen() is SpectatorPlayer player)
|
||||
player.AllowFail();
|
||||
|
||||
Schedule(() =>
|
||||
if (this.GetChildScreen() is SpectatorPlayerLoader loader)
|
||||
{
|
||||
scheduledStart?.Cancel();
|
||||
immediateSpectatorGameplayState = null;
|
||||
clearDisplay();
|
||||
});
|
||||
if (loader.GetChildScreen() is SpectatorPlayer player)
|
||||
{
|
||||
player.AllowFail();
|
||||
resetStartState();
|
||||
}
|
||||
else
|
||||
QuitGameplay(userId);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void QuitGameplay(int userId)
|
||||
{
|
||||
// Importantly, don't schedule this call, as a child screen may be present (and will cause the schedule to not be run as expected).
|
||||
this.MakeCurrent();
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
scheduledStart?.Cancel();
|
||||
immediateSpectatorGameplayState = null;
|
||||
|
||||
clearDisplay();
|
||||
});
|
||||
resetStartState();
|
||||
}
|
||||
|
||||
private void resetStartState() => Schedule(() =>
|
||||
{
|
||||
scheduledStart?.Cancel();
|
||||
immediateSpectatorGameplayState = null;
|
||||
clearDisplay();
|
||||
});
|
||||
|
||||
private void clearDisplay()
|
||||
{
|
||||
watchButton.Enabled.Value = false;
|
||||
|
Loading…
Reference in New Issue
Block a user