From 3fa6adc37fbe257cda7de47287256f2e1edd96dd Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 16 Jun 2023 04:37:21 -0400 Subject: [PATCH] Regression test for #1550 --- tests/DMAPI/LongRunning/Test.dm | 15 ++++ .../Live/Instance/WatchdogTest.cs | 86 ++++++++++++++----- 2 files changed, 81 insertions(+), 20 deletions(-) diff --git a/tests/DMAPI/LongRunning/Test.dm b/tests/DMAPI/LongRunning/Test.dm index b81b7f3f42..ef653c1efc 100644 --- a/tests/DMAPI/LongRunning/Test.dm +++ b/tests/DMAPI/LongRunning/Test.dm @@ -128,6 +128,12 @@ var/run_bridge_test var/list/channels = TgsChatChannelInfo() return "[length(channels)]" + var/legalize_nuclear_bombs = data["shadow_wizard_money_gang"] + if(legalize_nuclear_bombs) + text2file("I expect this to remain here for a while", "kajigger.txt") + kajigger_test = TRUE + return "we love casting spells" + TgsChatBroadcast(new /datum/tgs_message_content("Recieved non-tgs topic: `[T]`")) return "feck" @@ -147,10 +153,18 @@ var/run_bridge_test world.TgsChatBroadcast(new /datum/tgs_message_content("2/3 queued detached chat messages")) world.TgsChatBroadcast(new /datum/tgs_message_content("3/3 queued detached chat messages")) +var/kajigger_test = FALSE + /world/Reboot(reason) TgsChatBroadcast("World Rebooting") + + if(kajigger_test && !fexists("kajigger.txt")) + FailTest("TGS STOLE MY KAJIGGER (#1548 regression)") + TgsReboot() + ..() + /datum/tgs_event_handler/impl/HandleEvent(event_code, ...) set waitfor = FALSE @@ -175,6 +189,7 @@ var/run_bridge_test world.log << "Done sleep, calling Reboot" world.Reboot() + /datum/tgs_chat_command/embeds_test name = "embeds_test" help_text = "dumps an embed" diff --git a/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs index b9278aec6d..4e59572eac 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs @@ -102,6 +102,8 @@ namespace Tgstation.Server.Tests.Live.Instance { await StartAndLeaveRunning(cancellationToken); + await RegressionTest1550(cancellationToken); + var deleteJobTask = TestDeleteByondInstallErrorCasesAndQueing(cancellationToken); SessionController.LogTopicRequests = false; @@ -127,6 +129,54 @@ namespace Tgstation.Server.Tests.Live.Instance await WaitForJob(restartJob, 15, false, null, cancellationToken); } + async ValueTask RegressionTest1550(CancellationToken cancellationToken) + { + // we need to cycle deployments twice because TGS holds the initial deployment + var job = await DeployTestDme("LongRunning/long_running_test", DreamDaemonSecurity.Trusted, true, cancellationToken); + var currentStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + + Assert.AreEqual(WatchdogStatus.Online, currentStatus.Status); + Assert.IsNotNull(currentStatus.StagedCompileJob); + var expectedStaged = currentStatus.StagedCompileJob; + Assert.AreNotEqual(expectedStaged.Id, currentStatus.ActiveCompileJob.Id); + + await TellWorldToReboot(cancellationToken); + + currentStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + Assert.AreEqual(expectedStaged.Id, currentStatus.ActiveCompileJob.Id); + + await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken); + + var topicRequestResult = await TopicClient.SendTopic( + IPAddress.Loopback, + $"shadow_wizard_money_gang=1", + TestLiveServer.DDPort, + cancellationToken); + + Assert.IsNotNull(topicRequestResult); + Assert.AreEqual("we love casting spells", topicRequestResult.StringData); + + await DeployTestDme("LongRunning/long_running_test", DreamDaemonSecurity.Trusted, true, cancellationToken); + + currentStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + + Assert.AreEqual(WatchdogStatus.Online, currentStatus.Status); + Assert.IsNotNull(currentStatus.StagedCompileJob); + Assert.AreEqual(expectedStaged.Id, currentStatus.ActiveCompileJob.Id); + expectedStaged = currentStatus.StagedCompileJob; + Assert.AreNotEqual(expectedStaged.Id, currentStatus.ActiveCompileJob.Id); + + await TellWorldToReboot(cancellationToken); + + currentStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + Assert.AreEqual(WatchdogStatus.Online, currentStatus.Status); + Assert.IsNull(currentStatus.StagedCompileJob); + Assert.AreEqual(expectedStaged.Id, currentStatus.ActiveCompileJob.Id); + + await CheckDMApiFail(currentStatus.ActiveCompileJob, cancellationToken, false); + await CheckDMApiFail(expectedStaged, cancellationToken, false); + } + async Task TestDeleteByondInstallErrorCasesAndQueing(CancellationToken cancellationToken) { var testCustomVersion = new Version(ByondTest.TestVersion.Major, ByondTest.TestVersion.Minor, 1); @@ -950,32 +1000,28 @@ namespace Tgstation.Server.Tests.Live.Instance public async Task TellWorldToReboot(CancellationToken cancellationToken) { var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + Assert.IsNotNull(daemonStatus.StagedCompileJob); var initialCompileJob = daemonStatus.ActiveCompileJob; - try - { - System.Console.WriteLine("TEST: Sending world reboot topic..."); - var result = await TopicClient.SendTopic(IPAddress.Loopback, "tgs_integration_test_special_tactics=1", TestLiveServer.DDPort, cancellationToken); - Assert.AreEqual("ack", result.StringData); + System.Console.WriteLine("TEST: Sending world reboot topic..."); + var result = await TopicClient.SendTopic(IPAddress.Loopback, "tgs_integration_test_special_tactics=1", TestLiveServer.DDPort, cancellationToken); + Assert.AreEqual("ack", result.StringData); - using (var tempCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) - using (tempCts.Token.Register(() => System.Console.WriteLine("TEST ERROR: Timeout in TellWorldToReboot!"))) + using var tempCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + var tempToken = tempCts.Token; + using (tempToken.Register(() => System.Console.WriteLine("TEST ERROR: Timeout in TellWorldToReboot!"))) + { + tempCts.CancelAfter(TimeSpan.FromMinutes(2)); + + do { - tempCts.CancelAfter(TimeSpan.FromMinutes(2)); - var tempToken = tempCts.Token; - - do - { - await Task.Delay(TimeSpan.FromSeconds(1), tempToken); - daemonStatus = await instanceClient.DreamDaemon.Read(tempToken); - } - while (initialCompileJob.Id == daemonStatus.ActiveCompileJob.Id); + await Task.Delay(TimeSpan.FromSeconds(1), tempToken); + daemonStatus = await instanceClient.DreamDaemon.Read(tempToken); } + while (initialCompileJob.Id == daemonStatus.ActiveCompileJob.Id); } - catch (OperationCanceledException) - { - throw; - } + + await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken); return daemonStatus; }