From 80940a8d8a729b82045802f9dc987f978abfa375 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Tue, 25 Aug 2020 15:26:33 +0200 Subject: [PATCH] Add restart round command test (#1897) --- .../Tests/Commands/RestartRoundTest.cs | 62 +++++++++++++++++++ .../GameTicking/GameTickerCommands.cs | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Content.IntegrationTests/Tests/Commands/RestartRoundTest.cs diff --git a/Content.IntegrationTests/Tests/Commands/RestartRoundTest.cs b/Content.IntegrationTests/Tests/Commands/RestartRoundTest.cs new file mode 100644 index 0000000000..83e4d111bb --- /dev/null +++ b/Content.IntegrationTests/Tests/Commands/RestartRoundTest.cs @@ -0,0 +1,62 @@ +using System.Threading.Tasks; +using Content.Server.GameTicking; +using Content.Server.Interfaces.GameTicking; +using NUnit.Framework; +using Robust.Shared.Interfaces.Configuration; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Timing; + +namespace Content.IntegrationTests.Tests.Commands +{ + [TestFixture] + [TestOf(typeof(NewRoundCommand))] + public class RestartRoundTest : ContentIntegrationTest + { + [Test] + [TestCase(true)] + [TestCase(false)] + public async Task RestartRoundAfterStart(bool lobbyEnabled) + { + var server = StartServer(); + + await server.WaitIdleAsync(); + + var gameTicker = server.ResolveDependency(); + var configManager = server.ResolveDependency(); + var entityManager = server.ResolveDependency(); + + await server.WaitRunTicks(30); + + GameTick tickBeforeRestart = default; + + server.Assert(() => + { + configManager.SetCVar("game.lobbyenabled", lobbyEnabled); + + Assert.That(gameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound)); + + tickBeforeRestart = entityManager.CurrentTick; + + var command = new NewRoundCommand(); + command.Execute(null, null, new string[] { }); + + if (lobbyEnabled) + { + Assert.That(gameTicker.RunLevel, Is.Not.EqualTo(GameRunLevel.InRound)); + } + }); + + await server.WaitIdleAsync(); + await server.WaitRunTicks(5); + + server.Assert(() => + { + var tickAfterRestart = entityManager.CurrentTick; + + Assert.That(tickBeforeRestart < tickAfterRestart); + }); + + await server.WaitRunTicks(60); + } + } +} diff --git a/Content.Server/GameTicking/GameTickerCommands.cs b/Content.Server/GameTicking/GameTickerCommands.cs index 2e3b0d78d0..b8d073af9e 100644 --- a/Content.Server/GameTicking/GameTickerCommands.cs +++ b/Content.Server/GameTicking/GameTickerCommands.cs @@ -99,7 +99,7 @@ namespace Content.Server.GameTicking } } - class NewRoundCommand : IClientCommand + public class NewRoundCommand : IClientCommand { public string Command => "restartround"; public string Description => "Moves the server from PostRound to a new PreRoundLobby.";