Rework OD test to be alongside main tests

Fix a bunch of VS messages too
This commit is contained in:
Jordan Dominion
2023-10-14 12:17:32 -04:00
parent 59cefa9f4f
commit 22f9a3bc61
3 changed files with 61 additions and 70 deletions
@@ -26,30 +26,21 @@ using Tgstation.Server.Host.System;
namespace Tgstation.Server.Tests.Live.Instance
{
sealed class ByondTest : JobsRequiredTest
sealed class ByondTest(IByondClient byondClient, IJobsClient jobsClient, IFileDownloader fileDownloader, Api.Models.Instance metadata, EngineType engineType) : JobsRequiredTest(jobsClient)
{
readonly IByondClient byondClient;
readonly IFileDownloader fileDownloader;
readonly IByondClient byondClient = byondClient ?? throw new ArgumentNullException(nameof(byondClient));
readonly IFileDownloader fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader));
readonly Api.Models.Instance metadata;
readonly Api.Models.Instance metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
static Dictionary<EngineType, ByondVersion> edgeVersions = new Dictionary<EngineType, ByondVersion>
static readonly Dictionary<EngineType, ByondVersion> edgeVersions = new ()
{
{ EngineType.Byond, null },
{ EngineType.OpenDream, null }
};
ByondVersion testVersion;
EngineType testEngine;
public ByondTest(IByondClient byondClient, IJobsClient jobsClient, IFileDownloader fileDownloader, Api.Models.Instance metadata, EngineType engineType)
: base(jobsClient)
{
this.byondClient = byondClient ?? throw new ArgumentNullException(nameof(byondClient));
this.fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader));
this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
testEngine = engineType;
}
readonly EngineType testEngine = engineType;
public Task Run(CancellationToken cancellationToken, out Task firstInstall)
{
@@ -76,9 +67,7 @@ namespace Tgstation.Server.Tests.Live.Instance
var targetVersion = splits.Last();
var badVersionMap = new PlatformIdentifier().IsWindows
? new Dictionary<string, string>()
{
}
? []
// linux map also needs updating in CI
: new Dictionary<string, string>()
{
@@ -108,6 +97,7 @@ namespace Tgstation.Server.Tests.Live.Instance
return null;
}
global::System.Console.WriteLine($"Edge {engineType} version evalutated to {byondVersion}");
return edgeVersions[engineType] = byondVersion;
}
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -23,20 +24,12 @@ using Tgstation.Server.Host.System;
namespace Tgstation.Server.Tests.Live.Instance
{
sealed class InstanceTest
sealed class InstanceTest(IInstanceManagerClient instanceManagerClient, IFileDownloader fileDownloader, InstanceManager instanceManager, ushort serverPort)
{
readonly IInstanceManagerClient instanceManagerClient;
readonly IFileDownloader fileDownloader;
readonly InstanceManager instanceManager;
readonly ushort serverPort;
public InstanceTest(IInstanceManagerClient instanceManagerClient, IFileDownloader fileDownloader, InstanceManager instanceManager, ushort serverPort)
{
this.instanceManagerClient = instanceManagerClient ?? throw new ArgumentNullException(nameof(instanceManagerClient));
this.fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader));
this.instanceManager = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager));
this.serverPort = serverPort;
}
readonly IInstanceManagerClient instanceManagerClient = instanceManagerClient ?? throw new ArgumentNullException(nameof(instanceManagerClient));
readonly IFileDownloader fileDownloader = fileDownloader ?? throw new ArgumentNullException(nameof(fileDownloader));
readonly InstanceManager instanceManager = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager));
readonly ushort serverPort = serverPort;
public async Task RunTests(
IInstanceClient instanceClient,
@@ -44,10 +37,9 @@ namespace Tgstation.Server.Tests.Live.Instance
ushort ddPort,
bool highPrioDD,
bool lowPrioDeployment,
EngineType engineType,
CancellationToken cancellationToken)
{
var byondTest = new ByondTest(instanceClient.Byond, instanceClient.Jobs, fileDownloader, instanceClient.Metadata, engineType);
var byondTest = new ByondTest(instanceClient.Byond, instanceClient.Jobs, fileDownloader, instanceClient.Metadata, EngineType.Byond);
var chatTest = new ChatTest(instanceClient.ChatBots, instanceManagerClient, instanceClient.Jobs, instanceClient.Metadata);
var configTest = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata);
var repoTest = new RepositoryTest(instanceClient.Repository, instanceClient.Jobs);
@@ -68,30 +60,29 @@ namespace Tgstation.Server.Tests.Live.Instance
await byondTask;
await new WatchdogTest(
await ByondTest.GetEdgeVersion(engineType, fileDownloader, cancellationToken), instanceClient, instanceManager, serverPort, highPrioDD, ddPort).Run(cancellationToken);
await ByondTest.GetEdgeVersion(EngineType.Byond, fileDownloader, cancellationToken), instanceClient, instanceManager, serverPort, highPrioDD, ddPort).Run(cancellationToken);
}
public async Task RunCompatTests(
Version compatByondVersion,
ByondVersion compatVersion,
IInstanceClient instanceClient,
ushort dmPort,
ushort ddPort,
bool highPrioDD,
CancellationToken cancellationToken)
{
var compatVersion = new ByondVersion
{
Engine = EngineType.Byond,
Version = compatByondVersion,
};
if (compatVersion.Engine != EngineType.Byond)
#if !DEBUG
Assert.Fail("Compat test for OD not release ready!");
#else
return;
#endif
System.Console.WriteLine($"COMPAT TEST START: {compatVersion}");
const string Origin = "https://github.com/Cyberboss/common_core";
var cloneRequest = instanceClient.Repository.Clone(new RepositoryCreateRequest
{
Origin = new Uri(Origin),
}, cancellationToken);
}, cancellationToken).AsTask();
var dmUpdateRequest = instanceClient.DreamMaker.Update(new DreamMakerRequest
{
@@ -122,7 +113,7 @@ namespace Tgstation.Server.Tests.Live.Instance
ChannelLimit = 10,
Channels = new List<ChatChannel>
{
new ChatChannel
new ()
{
ChannelData = channelIdStr,
Tag = "some_tag",
@@ -180,7 +171,7 @@ namespace Tgstation.Server.Tests.Live.Instance
jrt.WaitForJob(cloneRequest.Result.ActiveJob, 60, false, null, cancellationToken),
jrt.WaitForJob(theJobWeWant, 30, false, null, cancellationToken),
dmUpdateRequest.AsTask(),
cloneRequest.AsTask());
cloneRequest);
var configSetupTask = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata).SetupDMApiTests(cancellationToken);
@@ -56,7 +56,7 @@ namespace Tgstation.Server.Tests.Live
static readonly ushort compatDMPort = FreeTcpPort(mainDDPort, mainDMPort);
static readonly ushort compatDDPort = FreeTcpPort(mainDDPort, mainDMPort, compatDMPort);
readonly IServerClientFactory clientFactory = new ServerClientFactory(new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version.ToString()));
readonly ServerClientFactory clientFactory = new (new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Version.ToString()));
public static List<System.Diagnostics.Process> GetDDProcessesOnPort(ushort? port)
{
@@ -956,12 +956,7 @@ namespace Tgstation.Server.Tests.Live
}
[TestMethod]
public Task TestStandardTgsOperation() => TestStandardTgsOperation(EngineType.Byond);
[TestMethod]
public Task TestOpenDreamTgsOperation() => TestStandardTgsOperation(EngineType.OpenDream);
async Task TestStandardTgsOperation(EngineType engineType)
public async Task TestStandardTgsOperation()
{
using(var currentProcess = System.Diagnostics.Process.GetCurrentProcess())
{
@@ -986,7 +981,7 @@ namespace Tgstation.Server.Tests.Live
ServiceCollectionExtensions.UseAdditionalLoggerProvider<HardFailLoggerProvider>();
var failureTask = HardFailLoggerProvider.FailureSource;
var internalTask = TestTgsInternal(engineType, hardCancellationToken);
var internalTask = TestTgsInternal(hardCancellationToken);
await Task.WhenAny(
internalTask,
failureTask);
@@ -1018,7 +1013,7 @@ namespace Tgstation.Server.Tests.Live
await internalTask;
}
async Task TestTgsInternal(EngineType engineType, CancellationToken hardCancellationToken)
async Task TestTgsInternal(CancellationToken hardCancellationToken)
{
var discordConnectionString = Environment.GetEnvironmentVariable("TGS_TEST_DISCORD_TOKEN");
var ircConnectionString = Environment.GetEnvironmentVariable("TGS_TEST_IRC_CONNECTION_STRING");
@@ -1046,19 +1041,15 @@ namespace Tgstation.Server.Tests.Live
Assert.IsTrue(new IrcConnectionStringBuilder(ircConnectionString).Valid);
}
if (engineType == EngineType.Byond)
var procs = System.Diagnostics.Process.GetProcessesByName("byond");
if (procs.Length != 0)
{
var procs = System.Diagnostics.Process.GetProcessesByName("byond");
if (procs.Any())
{
foreach (var proc in procs)
proc.Dispose();
foreach (var proc in procs)
proc.Dispose();
// Inconclusive and not fail because we don't want to unexpectedly kill a dev's BYOND.exe
Assert.Inconclusive("Cannot run server test because DreamDaemon will not start headless while the BYOND pager is running!");
}
// Inconclusive and not fail because we don't want to unexpectedly kill a dev's BYOND.exe
Assert.Inconclusive("Cannot run server test because DreamDaemon will not start headless while the BYOND pager is running!");
}
using var server = new LiveTestingServer(null, true);
using var serverCts = CancellationTokenSource.CreateLinkedTokenSource(hardCancellationToken);
@@ -1127,12 +1118,16 @@ namespace Tgstation.Server.Tests.Live
async Task RunInstanceTests()
{
// Some earlier linux BYOND versions have a critical bug where replacing the directory in non-basic watchdogs causes the DreamDaemon cwd to change
var canRunCompatTests = engineType == EngineType.Byond && new PlatformIdentifier().IsWindows;
var canRunCompatTests = new PlatformIdentifier().IsWindows;
var compatTests = canRunCompatTests
? FailFast(
instanceTest
.RunCompatTests(
new Version(510, 1346),
new ByondVersion
{
Engine = EngineType.Byond,
Version = new Version(510, 1346)
},
adminClient.Instances.CreateClient(compatInstance),
compatDMPort,
compatDDPort,
@@ -1143,6 +1138,21 @@ namespace Tgstation.Server.Tests.Live
if (TestingUtils.RunningInGitHubActions) // they only have 2 cores, can't handle intense parallelization
await compatTests;
var odCompatTests = canRunCompatTests
? FailFast(
instanceTest
.RunCompatTests(
await ByondTest.GetEdgeVersion(EngineType.OpenDream, fileDownloader, cancellationToken),
adminClient.Instances.CreateClient(compatInstance),
compatDMPort,
compatDDPort,
server.HighPriorityDreamDaemon,
cancellationToken))
: Task.CompletedTask;
if (TestingUtils.RunningInGitHubActions) // they only have 2 cores, can't handle intense parallelization
await odCompatTests;
await FailFast(
instanceTest
.RunTests(
@@ -1151,10 +1161,10 @@ namespace Tgstation.Server.Tests.Live
mainDDPort,
server.HighPriorityDreamDaemon,
server.LowPriorityDeployments,
engineType,
cancellationToken));
await compatTests;
await odCompatTests;
}
var instanceTests = RunInstanceTests();
@@ -1221,7 +1231,7 @@ namespace Tgstation.Server.Tests.Live
var instanceClient = adminClient.Instances.CreateClient(instance);
var jobs = await instanceClient.Jobs.ListActive(null, cancellationToken);
if (!jobs.Any())
if (jobs.Count == 0)
{
var entities = await instanceClient.Jobs.List(null, cancellationToken);
var getTasks = entities
@@ -1293,7 +1303,7 @@ namespace Tgstation.Server.Tests.Live
async Task WaitForInitialJobs(IInstanceClient instanceClient)
{
var jobs = await instanceClient.Jobs.ListActive(null, cancellationToken);
if (!jobs.Any())
if (jobs.Count == 0)
{
var entities = await instanceClient.Jobs.List(null, cancellationToken);
var getTasks = entities
@@ -1318,7 +1328,7 @@ namespace Tgstation.Server.Tests.Live
preStartupTime = DateTimeOffset.UtcNow;
serverTask = server.Run(cancellationToken).AsTask();
long expectedCompileJobId, expectedStaged;
var edgeVersion = await ByondTest.GetEdgeVersion(engineType, fileDownloader, cancellationToken);
var edgeVersion = await ByondTest.GetEdgeVersion(EngineType.Byond, fileDownloader, cancellationToken);
using (var adminClient = await CreateAdminClient(server.Url, cancellationToken))
{
var instanceClient = adminClient.Instances.CreateClient(instance);