diff --git a/tests/DMAPI/LongRunning/Test.dm b/tests/DMAPI/LongRunning/Test.dm index 657fadbfd0..f605c5ad59 100644 --- a/tests/DMAPI/LongRunning/Test.dm +++ b/tests/DMAPI/LongRunning/Test.dm @@ -31,6 +31,23 @@ if(!fexists("[DME_NAME].rsc")) FailTest("Failed to create .rsc!") +#ifdef RUN_STATIC_FILE_TESTS + if(params["expect_static_files"]) + if(!fexists("test2.txt")) + FailTest("Missing test2.txt") + + var/f2content = file2text("test2.txt") + if(f2content != "bbb") + FailTest("Unexpected test2.txt content: [f2content]") + + if(!fexists("data/test.txt")) + FailTest("Missing data/test.txt") + + var/f1content = file2text("data/test.txt") + if(f1content != "aaa") + FailTest("Unexpected data/test.txt content: [f1content]") +#endif + StartAsync() /proc/dab() diff --git a/tests/DMAPI/LongRunning/long_running_test_rooted.dme b/tests/DMAPI/LongRunning/long_running_test_rooted.dme index d8e9d61c96..a2ff783588 100644 --- a/tests/DMAPI/LongRunning/long_running_test_rooted.dme +++ b/tests/DMAPI/LongRunning/long_running_test_rooted.dme @@ -11,6 +11,8 @@ // END_PREFERENCES // BEGIN_INCLUDE +#define RUN_STATIC_FILE_TESTS +#define DME_NAME "long_running_test_rooted" #include "tests/DMAPI/LongRunning/Config.dm" #include "tests/DMAPI/test_prelude.dm" #include "tests/DMAPI/LongRunning/Test.dm" diff --git a/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs index 2dea3e5b12..44c2f7246b 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs @@ -83,19 +83,40 @@ namespace Tgstation.Server.Tests.Live.Instance var path = Path.Combine(instance.Path, "Configuration", tmp); Assert.IsFalse(Directory.Exists(path)); - // leave a directory there to test the deployment process - var staticDir = new ConfigurationFileRequest - { - Path = "/GameStaticFiles/data" - }; - - await configurationClient.CreateDirectory(staticDir, cancellationToken); } public Task SetupDMApiTests(bool includingRoot, CancellationToken cancellationToken) { // just use an I/O manager here var ioManager = new DefaultIOManager(); + + async Task TestStaticFileAndDir() + { + // leave a file there to test the deployment process + var staticDir = new ConfigurationFileRequest + { + Path = "/GameStaticFiles/data" + }; + + await configurationClient.CreateDirectory(staticDir, cancellationToken); + + var staticFile = new ConfigurationFileRequest + { + Path = "/GameStaticFiles/data/test.txt" + }; + + await using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes("aaa")); + await configurationClient.Write(staticFile, memoryStream, cancellationToken); + + var staticFile2 = new ConfigurationFileRequest + { + Path = "/GameStaticFiles/test2.txt" + }; + + await using var memoryStream2 = new MemoryStream(Encoding.UTF8.GetBytes("bbb")); + await configurationClient.Write(staticFile2, memoryStream2, cancellationToken); + } + return Task.WhenAll( ioManager.CopyDirectory( Enumerable.Empty(), @@ -110,6 +131,9 @@ namespace Tgstation.Server.Tests.Live.Instance ioManager.ConcatPath(instance.Path, "Repository", "long_running_test_rooted.dme"), cancellationToken) : Task.CompletedTask, + includingRoot + ? TestStaticFileAndDir() + : Task.CompletedTask, ioManager.CopyDirectory( Enumerable.Empty(), null, diff --git a/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs index 784fce5f67..35bd51fd11 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/WatchdogTest.cs @@ -114,7 +114,7 @@ namespace Tgstation.Server.Tests.Live.Instance Port = ddPort, MapThreads = 2, LogOutput = false, - AdditionalParameters = "expect_chat_channels=1" + AdditionalParameters = "expect_chat_channels=1&expect_static_files=1" }, cancellationToken), CheckByondVersions(), ApiAssert.ThrowsException(() => instanceClient.DreamDaemon.Update(new DreamDaemonRequest @@ -157,8 +157,64 @@ namespace Tgstation.Server.Tests.Live.Instance System.Console.WriteLine($"TEST: END WATCHDOG TESTS {instanceClient.Metadata.Name}"); } + async ValueTask RegressionTest1686(CancellationToken cancellationToken) + { + async ValueTask RunTest(bool useTrusted) + { + System.Console.WriteLine($"TEST: RegressionTest1686 {useTrusted}..."); + var ddUpdateTask = instanceClient.DreamDaemon.Update(new DreamDaemonRequest + { + SecurityLevel = useTrusted ? DreamDaemonSecurity.Trusted : DreamDaemonSecurity.Safe, + AdditionalParameters = "expect_chat_channels=1&expect_static_files=1", + }, cancellationToken); + var currentStatus = await DeployTestDme("long_running_test_rooted", DreamDaemonSecurity.Trusted, true, cancellationToken); + await ddUpdateTask; + + Assert.AreEqual(WatchdogStatus.Offline, currentStatus.Status); + + var startJob = await StartDD(cancellationToken); + + await WaitForJob(startJob, 40, false, null, cancellationToken); + + currentStatus = await instanceClient.DreamDaemon.Update(new DreamDaemonRequest + { + SoftShutdown = true, + }, cancellationToken); + + Assert.AreEqual(WatchdogStatus.Online, currentStatus.Status); + + // reimplement TellWorldToReboot because it expects a new deployment and we don't care + System.Console.WriteLine("TEST: Hack world reboot topic..."); + var result = await topicClient.SendTopic(IPAddress.Loopback, "tgs_integration_test_special_tactics=1", ddPort, cancellationToken); + Assert.AreEqual("ack", result.StringData); + + using var tempCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + var tempToken = tempCts.Token; + using (tempToken.Register(() => System.Console.WriteLine("TEST ERROR: Timeout in RegressionTest1686!"))) + { + tempCts.CancelAfter(TimeSpan.FromMinutes(2)); + + do + { + await Task.Delay(TimeSpan.FromSeconds(1), tempToken); + currentStatus = await instanceClient.DreamDaemon.Read(tempToken); + } + while (currentStatus.Status != WatchdogStatus.Offline); + } + + await CheckDMApiFail(currentStatus.ActiveCompileJob, cancellationToken); + } + + await RunTest(true); + + if (new PlatformIdentifier().IsWindows || !usingBasicWatchdog) + await RunTest(false); + } + async Task InteropTestsForLongRunningDme(CancellationToken cancellationToken) { + await RegressionTest1686(cancellationToken); + await StartAndLeaveRunning(cancellationToken); await RegressionTest1550(cancellationToken); @@ -191,8 +247,7 @@ namespace Tgstation.Server.Tests.Live.Instance async ValueTask RegressionTest1550(CancellationToken cancellationToken) { // we need to cycle deployments twice because TGS holds the initial deployment - await DeployTestDme("LongRunning/long_running_test", DreamDaemonSecurity.Trusted, true, cancellationToken); - var currentStatus = await instanceClient.DreamDaemon.Read(cancellationToken); + var currentStatus = await DeployTestDme("LongRunning/long_running_test", DreamDaemonSecurity.Trusted, true, cancellationToken); Assert.AreEqual(WatchdogStatus.Online, currentStatus.Status); Assert.IsNotNull(currentStatus.StagedCompileJob);