tgstation-server
The /tg/station 13 server suite
ByondTest.cs
Go to the documentation of this file.
1 using Microsoft.VisualStudio.TestTools.UnitTesting;
2 using System;
3 using System.Threading;
4 using System.Threading.Tasks;
6 
8 {
9  sealed class ByondTest
10  {
13 
15  {
16  this.byondClient = byondClient ?? throw new ArgumentNullException(nameof(byondClient));
17  this.jobsClient = jobsClient ?? throw new ArgumentNullException(nameof(jobsClient));
18  }
19 
20  public async Task Run(CancellationToken cancellationToken)
21  {
22  await TestNoVersion(cancellationToken).ConfigureAwait(false);
23  await TestInstall511(cancellationToken).ConfigureAwait(false);
24  }
25 
26  async Task TestInstall511(CancellationToken cancellationToken)
27  {
28  var newModel = new Api.Models.Byond
29  {
30  Version = new Version(511, 1385)
31  };
32  var test = await byondClient.SetActiveVersion(newModel, cancellationToken).ConfigureAwait(false);
33  Assert.IsNotNull(test.InstallJob);
34  Assert.IsNull(test.Version);
35  var job = test.InstallJob;
36  var maxWait = 60; //it's 10MB max give me a break
37  do
38  {
39  await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
40  job = await jobsClient.GetId(job, cancellationToken).ConfigureAwait(false);
41  --maxWait;
42  }
43  while (!job.StoppedAt.HasValue && maxWait > 0);
44  if (!job.StoppedAt.HasValue)
45  {
46  await jobsClient.Cancel(job, cancellationToken).ConfigureAwait(false);
47  Assert.Fail("Byond installation job timed out!");
48  }
49 
50  if (job.ExceptionDetails != null)
51  Assert.Fail(job.ExceptionDetails);
52 
53  var currentShit = await byondClient.ActiveVersion(cancellationToken).ConfigureAwait(false);
54  Assert.AreEqual(newModel.Version, currentShit.Version);
55  }
56 
57  async Task TestNoVersion(CancellationToken cancellationToken)
58  {
59  var allVersionsTask = byondClient.InstalledVersions(cancellationToken);
60  var currentShit = await byondClient.ActiveVersion(cancellationToken).ConfigureAwait(false);
61  Assert.IsNotNull(currentShit);
62  Assert.IsNull(currentShit.InstallJob);
63  Assert.IsNull(currentShit.Version);
64  var otherShit = await allVersionsTask.ConfigureAwait(false);
65  Assert.IsNotNull(otherShit);
66  Assert.AreEqual(0, otherShit.Count);
67  }
68  }
69 }
For managing the Byond installation
Definition: IByondClient.cs:11
Task< IReadOnlyList< Byond > > InstalledVersions(CancellationToken cancellationToken)
Get all installed Byond System.Versions
Task< Job > GetId(EntityId job, CancellationToken cancellationToken)
Get a job
ByondTest(IByondClient byondClient, IJobsClient jobsClient)
Definition: ByondTest.cs:14
async Task TestInstall511(CancellationToken cancellationToken)
Definition: ByondTest.cs:26
async Task TestNoVersion(CancellationToken cancellationToken)
Definition: ByondTest.cs:57
Task< Byond > ActiveVersion(CancellationToken cancellationToken)
Get the Byond active System.Version information
Task< Byond > SetActiveVersion(Byond byond, CancellationToken cancellationToken)
Updates the Byond information
async Task Run(CancellationToken cancellationToken)
Definition: ByondTest.cs:20
Task Cancel(Job job, CancellationToken cancellationToken)
Cancels a job