mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 23:17:20 +01:00
More test stuff
This commit is contained in:
@@ -18,3 +18,16 @@
|
||||
|
||||
/world/Reboot(reason)
|
||||
TgsReboot()
|
||||
|
||||
/datum/tgs_chat_command/reboot
|
||||
name = "echo"
|
||||
help_text = "echos input parameters"
|
||||
|
||||
/datum/tgs_chat_command/reboot/Run(datum/tgs_chat_user/sender, params)
|
||||
set waitfor = FALSE
|
||||
RebootAsync()
|
||||
return "Echo: [sender.channel.connection_name]|[sender.channel.friendly_name]|[sender.friendly_name]: [params]. Rebooting..."
|
||||
|
||||
/proc/RebootAsync()
|
||||
sleep(30)
|
||||
world.Reboot()
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client.Components;
|
||||
using Tgstation.Server.Host.Components.Chat.Providers;
|
||||
using Tgstation.Server.Host.Components.Interop;
|
||||
using Tgstation.Server.Host.Core;
|
||||
using Tgstation.Server.Host.System;
|
||||
|
||||
namespace Tgstation.Server.Tests.Instance
|
||||
{
|
||||
@@ -22,21 +29,12 @@ namespace Tgstation.Server.Tests.Instance
|
||||
public async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
await RunBasicTest(cancellationToken);
|
||||
await RunLongRunningTestThenUpdate(cancellationToken);
|
||||
}
|
||||
|
||||
async Task RunBasicTest(CancellationToken cancellationToken)
|
||||
{
|
||||
await instanceClient.DreamMaker.Update(new DreamMaker
|
||||
{
|
||||
ApiValidationSecurityLevel = DreamDaemonSecurity.Ultrasafe,
|
||||
ProjectName = "tests/DMAPI/BasicOperation/basic_operation_test"
|
||||
}, cancellationToken);
|
||||
|
||||
var compileJobJob = await instanceClient.DreamMaker.Compile(cancellationToken);
|
||||
|
||||
await WaitForJob(compileJobJob, 90, false, cancellationToken);
|
||||
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
var daemonStatus = await DeployTestDme("BasicOperation/basic_operation_test", DreamDaemonSecurity.Ultrasafe, cancellationToken);
|
||||
|
||||
Assert.IsNotNull(daemonStatus.ActiveCompileJob);
|
||||
Assert.AreEqual(DMApiConstants.Version, daemonStatus.ActiveCompileJob.DMApiVersion);
|
||||
@@ -51,6 +49,87 @@ namespace Tgstation.Server.Tests.Instance
|
||||
await CheckDMApiFail(daemonStatus.ActiveCompileJob, cancellationToken);
|
||||
}
|
||||
|
||||
async Task RunLongRunningTestThenUpdate(CancellationToken cancellationToken)
|
||||
{
|
||||
const string DmeName = "BasicOperation/basic_operation_test";
|
||||
|
||||
var daemonStatus = await DeployTestDme(DmeName, DreamDaemonSecurity.Trusted, cancellationToken);
|
||||
|
||||
var initialCompileJob = daemonStatus.ActiveCompileJob;
|
||||
Assert.IsNotNull(daemonStatus.ActiveCompileJob);
|
||||
Assert.AreEqual(DMApiConstants.Version, daemonStatus.ActiveCompileJob.DMApiVersion);
|
||||
Assert.AreEqual(DreamDaemonSecurity.Ultrasafe, daemonStatus.ActiveCompileJob.MinimumSecurityLevel);
|
||||
|
||||
var startJob = await instanceClient.DreamDaemon.Start(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await WaitForJob(startJob, 10, false, cancellationToken);
|
||||
|
||||
daemonStatus = await DeployTestDme(DmeName, DreamDaemonSecurity.Trusted, cancellationToken);
|
||||
|
||||
Assert.AreEqual(initialCompileJob.Id, daemonStatus.ActiveCompileJob.Id);
|
||||
Assert.AreNotEqual(initialCompileJob.Id, daemonStatus.StagedCompileJob.Id);
|
||||
|
||||
await SendCommandHack("reboot", false, cancellationToken);
|
||||
|
||||
await GracefulWatchdogShutdown(30, cancellationToken);
|
||||
}
|
||||
|
||||
async Task SendCommandHack(string message, bool useTgsGlobal, CancellationToken cancellationToken)
|
||||
{
|
||||
// tricky part, we need to get tgs to reboot.
|
||||
// We have a chat command to do this
|
||||
// But oh god i should be drawn and quartered for how i'm invoking it here
|
||||
// this assumes a purely open channel stored in the TGS4_TEST_IRC_CONNECTION_STRING
|
||||
|
||||
var connectionString = Environment.GetEnvironmentVariable("TGS4_TEST_IRC_CONNECTION_STRING");
|
||||
var builder = new IrcConnectionStringBuilder(connectionString);
|
||||
|
||||
using var provider = new IrcProvider(
|
||||
new AssemblyInformationProvider(),
|
||||
new AsyncDelayer(),
|
||||
Mock.Of<ILogger<IrcProvider>>(),
|
||||
builder.Address,
|
||||
builder.Port.Value,
|
||||
builder.Nickname + "_hack_other_user",
|
||||
null,
|
||||
null,
|
||||
10,
|
||||
builder.UseSsl.Value);
|
||||
|
||||
await provider.Connect(cancellationToken);
|
||||
|
||||
var channels = await provider.MapChannels(
|
||||
new List<ChatChannel>
|
||||
{
|
||||
new ChatChannel
|
||||
{
|
||||
IrcChannel = Environment.GetEnvironmentVariable("TGS4_IRC_CHAT_CHANNEL"),
|
||||
Tag = "ohgodohfuck",
|
||||
IsAdminChannel = false,
|
||||
IsUpdatesChannel = false,
|
||||
IsWatchdogChannel = false
|
||||
}
|
||||
},
|
||||
cancellationToken);
|
||||
|
||||
await provider.SendMessage(channels.First().RealId, $"!{(useTgsGlobal ? "tgs" : builder.Nickname)} {message}", cancellationToken);
|
||||
}
|
||||
|
||||
async Task<DreamDaemon> DeployTestDme(string dmeName, DreamDaemonSecurity deploymentSecurity, CancellationToken cancellationToken)
|
||||
{
|
||||
await instanceClient.DreamMaker.Update(new DreamMaker
|
||||
{
|
||||
ApiValidationSecurityLevel = deploymentSecurity,
|
||||
ProjectName = $"tests/DMAPI/{dmeName}"
|
||||
}, cancellationToken);
|
||||
|
||||
var compileJobJob = await instanceClient.DreamMaker.Compile(cancellationToken);
|
||||
|
||||
await WaitForJob(compileJobJob, 90, false, cancellationToken);
|
||||
|
||||
return await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
}
|
||||
|
||||
async Task GracefulWatchdogShutdown(uint timeout, CancellationToken cancellationToken)
|
||||
{
|
||||
await instanceClient.DreamDaemon.Update(new DreamDaemon
|
||||
|
||||
Reference in New Issue
Block a user