mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-23 04:57:17 +01:00
- Fix test issues.
- Fix non-swarm mode updates. - Add node ID logging context for live test.
This commit is contained in:
@@ -23,7 +23,16 @@ namespace Tgstation.Server.Host.Extensions
|
||||
/// <summary>
|
||||
/// Common template used for adding our custom log context to serilog.
|
||||
/// </summary>
|
||||
public const string SerilogContextTemplate = "(Instance:{Instance}|Job:{Job}|Request:{Request}|User:{User}|Monitor:{Monitor}|Bridge:{Bridge}|Chat:{ChatMessage}";
|
||||
/// <remarks>Should not be changed. Only mutable for the sake of identifying swarm nodes under a single test environment</remarks>
|
||||
public static string SerilogContextTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static members of the <see cref="ServiceCollectionExtensions"/> class.
|
||||
/// </summary>
|
||||
static ServiceCollectionExtensions()
|
||||
{
|
||||
SerilogContextTemplate = "(Instance:{Instance}|Job:{Job}|Request:{Request}|User:{User}|Monitor:{Monitor}|Bridge:{Bridge}|Chat:{ChatMessage}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a standard <typeparamref name="TConfig"/> binding.
|
||||
|
||||
@@ -59,6 +59,9 @@ namespace Tgstation.Server.Host.Swarm
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!SwarmMode)
|
||||
return true;
|
||||
|
||||
lock (swarmServers)
|
||||
return swarmServers.Count - 1 >= swarmConfiguration.UpdateRequiredNodeCount;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Serilog.Context;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -11,6 +14,7 @@ using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Host;
|
||||
using Tgstation.Server.Host.Configuration;
|
||||
using Tgstation.Server.Host.Core;
|
||||
using Tgstation.Server.Host.Extensions;
|
||||
using Tgstation.Server.Host.Setup;
|
||||
|
||||
namespace Tgstation.Server.Tests.Live
|
||||
@@ -32,8 +36,15 @@ namespace Tgstation.Server.Tests.Live
|
||||
readonly List<string> args;
|
||||
readonly List<string> swarmArgs;
|
||||
|
||||
string swarmNodeId;
|
||||
|
||||
public IServer RealServer { get; private set; }
|
||||
|
||||
static LiveTestingServer()
|
||||
{
|
||||
ServiceCollectionExtensions.SerilogContextTemplate += "|Node:{node}";
|
||||
}
|
||||
|
||||
public LiveTestingServer(SwarmConfiguration swarmConfiguration, bool enableOAuth, ushort port = 5010)
|
||||
{
|
||||
Directory = Environment.GetEnvironmentVariable("TGS_TEST_TEMP_DIRECTORY");
|
||||
@@ -146,6 +157,8 @@ namespace Tgstation.Server.Tests.Live
|
||||
|
||||
if (swarmConfiguration.UpdateRequiredNodeCount != 0)
|
||||
swarmArgs.Add($"Swarm:UpdateRequiredNodeCount={swarmConfiguration.UpdateRequiredNodeCount}");
|
||||
|
||||
swarmNodeId = swarmConfiguration.Identifier;
|
||||
}
|
||||
|
||||
public async Task RunNoArgumentsTest(CancellationToken cancellationToken)
|
||||
@@ -163,7 +176,8 @@ namespace Tgstation.Server.Tests.Live
|
||||
|
||||
public async Task Run(CancellationToken cancellationToken)
|
||||
{
|
||||
Console.WriteLine("TEST SERVER START");
|
||||
var messageAddition = swarmNodeId != null ? $": {swarmNodeId}" : String.Empty;
|
||||
Console.WriteLine("TEST SERVER START" + messageAddition);
|
||||
var firstRun = RealServer == null;
|
||||
var arrayArgs = args.Concat(swarmArgs).ToArray();
|
||||
RealServer = await Application
|
||||
@@ -176,8 +190,11 @@ namespace Tgstation.Server.Tests.Live
|
||||
if (firstRun)
|
||||
args[0] = string.Format(CultureInfo.InvariantCulture, "Database:DropDatabase={0}", false);
|
||||
|
||||
await RealServer.Run(cancellationToken);
|
||||
Console.WriteLine("TEST SERVER END");
|
||||
using (swarmNodeId != null
|
||||
? LogContext.PushProperty("node", swarmNodeId)
|
||||
: null)
|
||||
await RealServer.Run(cancellationToken);
|
||||
Console.WriteLine($"TEST SERVER END" + messageAddition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,22 +424,12 @@ namespace Tgstation.Server.Tests.Live
|
||||
using var controllerClient2 = await CreateAdminClient(controller.Url, cancellationToken);
|
||||
using var node1Client2 = await CreateAdminClient(node1.Url, cancellationToken);
|
||||
|
||||
await controllerClient2.Administration.Update(
|
||||
await ApiAssert.ThrowsException<ApiConflictException>(() => controllerClient2.Administration.Update(
|
||||
new ServerUpdateRequest
|
||||
{
|
||||
NewVersion = testUpdateVersion
|
||||
},
|
||||
cancellationToken);
|
||||
|
||||
// wait a few seconds and check we can do it again without getting ErrorCode.UpdateInProgress
|
||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||
|
||||
await controllerClient2.Administration.Update(
|
||||
new ServerUpdateRequest
|
||||
{
|
||||
NewVersion = testUpdateVersion
|
||||
},
|
||||
cancellationToken);
|
||||
cancellationToken), ErrorCode.SwarmIntegrityCheckFailed);
|
||||
|
||||
// regression: test updating also works from the controller
|
||||
serverTask = Task.WhenAll(
|
||||
@@ -492,7 +482,8 @@ namespace Tgstation.Server.Tests.Live
|
||||
{
|
||||
Address = controllerAddress,
|
||||
Identifier = "controller",
|
||||
PrivateKey = PrivateKey
|
||||
PrivateKey = PrivateKey,
|
||||
UpdateRequiredNodeCount = 2,
|
||||
}, false, 5011))
|
||||
{
|
||||
using var node1 = new LiveTestingServer(new SwarmConfiguration
|
||||
@@ -622,30 +613,16 @@ namespace Tgstation.Server.Tests.Live
|
||||
Task.Delay(TimeSpan.FromMinutes(1)));
|
||||
Assert.IsTrue(node1Task.IsCompleted);
|
||||
|
||||
// should remain registered
|
||||
// should have unregistered
|
||||
controllerInfo = await controllerClient2.ServerInformation(cancellationToken);
|
||||
Assert.AreEqual(2, controllerInfo.SwarmServers.Count);
|
||||
Assert.IsNotNull(controllerInfo.SwarmServers.SingleOrDefault(x => x.Identifier == "node2"));
|
||||
Assert.AreEqual(1, controllerInfo.SwarmServers.Count);
|
||||
Assert.IsNull(controllerInfo.SwarmServers.SingleOrDefault(x => x.Identifier == "node2"));
|
||||
|
||||
// update should fail
|
||||
await controllerClient2.Administration.Update(new ServerUpdateRequest
|
||||
await ApiAssert.ThrowsException<ApiConflictException>(() => controllerClient2.Administration.Update(new ServerUpdateRequest
|
||||
{
|
||||
NewVersion = new Version(4, 6, 2)
|
||||
}, cancellationToken);
|
||||
|
||||
async Task WaitForUpdateFailure()
|
||||
{
|
||||
ServerInformationResponse serverInformation;
|
||||
serverInformation = await controllerClient2.ServerInformation(cancellationToken);
|
||||
while (serverInformation.UpdateInProgress)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
|
||||
serverInformation = await controllerClient2.ServerInformation(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
var updateFailureTask = WaitForUpdateFailure();
|
||||
await Task.WhenAny(updateFailureTask, Task.Delay(TimeSpan.FromMinutes(5), cancellationToken));
|
||||
}, cancellationToken), ErrorCode.SwarmIntegrityCheckFailed);
|
||||
|
||||
node2Task = node2.Run(cancellationToken);
|
||||
using var node2Client2 = await CreateAdminClient(node2.Url, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user