From 16b66ec9db1f65ce3f3c4bea632a7149ad9fc3ea Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 14 Sep 2018 10:02:09 -0400 Subject: [PATCH] Adds some byond integration tests --- .../Instance/ByondTest.cs | 69 +++++++++++++++++++ .../Instance/InstanceTest.cs | 6 +- 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/Tgstation.Server.Tests/Instance/ByondTest.cs diff --git a/tests/Tgstation.Server.Tests/Instance/ByondTest.cs b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs new file mode 100644 index 0000000000..248a7c4f79 --- /dev/null +++ b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs @@ -0,0 +1,69 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Client.Components; + +namespace Tgstation.Server.Tests.Instance +{ + sealed class ByondTest + { + readonly IByondClient byondClient; + readonly IJobsClient jobsClient; + + public ByondTest(IByondClient byondClient, IJobsClient jobsClient) + { + this.byondClient = byondClient ?? throw new ArgumentNullException(nameof(byondClient)); + this.jobsClient = jobsClient ?? throw new ArgumentNullException(nameof(jobsClient)); + } + + public async Task Run(CancellationToken cancellationToken) + { + await TestNoVersion(cancellationToken).ConfigureAwait(false); + await TestInstall511(cancellationToken).ConfigureAwait(false); + } + + async Task TestInstall511(CancellationToken cancellationToken) + { + var newModel = new Api.Models.Byond + { + Version = new Version(511, 1385) + }; + var test = await byondClient.SetActiveVersion(newModel, cancellationToken).ConfigureAwait(false); + Assert.IsNotNull(test.InstallJob); + Assert.IsNull(test.Version); + var job = test.InstallJob; + var maxWait = 60; //it's 10MB max give me a break + do + { + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); + job = await jobsClient.GetId(job, cancellationToken).ConfigureAwait(false); + --maxWait; + } + while (!job.StoppedAt.HasValue && maxWait > 0); + if (!job.StoppedAt.HasValue) + { + await jobsClient.Cancel(job, cancellationToken).ConfigureAwait(false); + Assert.Fail("Byond installation job timed out!"); + } + + if (job.ExceptionDetails != null) + Assert.Fail(job.ExceptionDetails); + + var currentShit = await byondClient.ActiveVersion(cancellationToken).ConfigureAwait(false); + Assert.AreEqual(newModel.Version, currentShit.Version); + } + + async Task TestNoVersion(CancellationToken cancellationToken) + { + var allVersionsTask = byondClient.InstalledVersions(cancellationToken); + var currentShit = await byondClient.ActiveVersion(cancellationToken).ConfigureAwait(false); + Assert.IsNotNull(currentShit); + Assert.IsNull(currentShit.InstallJob); + Assert.IsNull(currentShit.Version); + var otherShit = await allVersionsTask.ConfigureAwait(false); + Assert.IsNotNull(otherShit); + Assert.AreEqual(0, otherShit.Count); + } + } +} diff --git a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs index cd65f015f2..8ca9076a30 100644 --- a/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/InstanceTest.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Client.Components; @@ -18,8 +16,12 @@ namespace Tgstation.Server.Tests.Instance public async Task RunTests(CancellationToken cancellationToken) { + var byondTests = new ByondTest(instanceClient.Byond, instanceClient.Jobs); var configTests = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata); + + var byondTest = byondTests.Run(cancellationToken); await configTests.Run(cancellationToken).ConfigureAwait(false); + await byondTest.ConfigureAwait(false); } } }