mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Remove CPU tracking. It's a nothing stat on multi-core systems
This commit is contained in:
@@ -65,11 +65,5 @@ namespace Tgstation.Server.Api.Models.Response
|
||||
/// </summary>
|
||||
[ResponseOptions]
|
||||
public long? ImmediateMemoryUsage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The CPU usage of the game server on a scale from 0-1.
|
||||
/// </summary>
|
||||
[ResponseOptions]
|
||||
public double? ImmediateCpuUsage { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,8 @@ namespace Tgstation.Server.Client.Components
|
||||
public ValueTask<JobResponse> Restart(CancellationToken cancellationToken) => apiClient.Patch<JobResponse>(Routes.DreamDaemon, instance.Id!.Value, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ValueTask<DreamDaemonResponse> Read(ulong? profileMs, CancellationToken cancellationToken) => apiClient.Read<DreamDaemonResponse>(
|
||||
profileMs.HasValue
|
||||
? $"{Routes.DreamDaemon}?profileMs={profileMs.Value}"
|
||||
: Routes.DreamDaemon,
|
||||
public ValueTask<DreamDaemonResponse> Read(CancellationToken cancellationToken) => apiClient.Read<DreamDaemonResponse>(
|
||||
Routes.DreamDaemon,
|
||||
instance.Id!.Value,
|
||||
cancellationToken);
|
||||
|
||||
|
||||
@@ -14,10 +14,9 @@ namespace Tgstation.Server.Client.Components
|
||||
/// <summary>
|
||||
/// Get the <see cref="DreamDaemonResponse"/> represented by the <see cref="IDreamDaemonClient"/>.
|
||||
/// </summary>
|
||||
/// <param name="profileMs">The amount of time to spend performance profiling.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="DreamDaemonResponse"/> information.</returns>
|
||||
ValueTask<DreamDaemonResponse> Read(ulong? profileMs = null, CancellationToken cancellationToken = default);
|
||||
ValueTask<DreamDaemonResponse> Read(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Start <see cref="DreamDaemonResponse"/>.
|
||||
|
||||
@@ -516,10 +516,6 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
return process.CreateDump(outputFile, minidump, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ValueTask<double> GetCpuUsage(TimeSpan waitingWindow, CancellationToken cancellationToken)
|
||||
=> process.GetCpuUsage(waitingWindow, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Task{TResult}"/> for <see cref="LaunchResult"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -24,6 +24,11 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
/// </summary>
|
||||
WatchdogStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the memory usage of the game server in bytes.
|
||||
/// </summary>
|
||||
long? MemoryUsage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// If the alpha server is the active server.
|
||||
/// </summary>
|
||||
@@ -102,13 +107,5 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the broadcast succeeded., <see langword="false"/> otherwise.</returns>
|
||||
ValueTask<bool> Broadcast(string message, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Profile memory and CPU usage of the running game server.
|
||||
/// </summary>
|
||||
/// <param name="timeSpan">The duration to profile the CPU usage of the game server for.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the performance metrics or <see langword="null"/> if the server is offline.</returns>
|
||||
Task<(long MemoryUsage, double CpuUsage)?> PerformanceProfile(TimeSpan timeSpan, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public long? MemoryUsage => GetActiveController()?.MemoryUsage;
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract bool AlphaIsActive { get; }
|
||||
|
||||
@@ -289,17 +292,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<(long MemoryUsage, double CpuUsage)?> PerformanceProfile(TimeSpan timeSpan, CancellationToken cancellationToken)
|
||||
{
|
||||
var controller = GetActiveController();
|
||||
if (controller == null)
|
||||
return null;
|
||||
|
||||
var cpuUsage = await controller.GetCpuUsage(timeSpan, cancellationToken);
|
||||
return (controller.MemoryUsage, CpuUsage: cpuUsage);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<MessageContent> HandleChatCommand(string commandName, string arguments, ChatUser sender, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -98,7 +98,6 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <summary>
|
||||
/// Get the watchdog status.
|
||||
/// </summary>
|
||||
/// <param name="profileMs">The amount of time to spend profiling game server CPU performance.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation.</returns>
|
||||
/// <response code="200">Read <see cref="DreamDaemonResponse"/> information successfully.</response>
|
||||
@@ -107,7 +106,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
[TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)]
|
||||
[ProducesResponseType(typeof(DreamDaemonResponse), 200)]
|
||||
[ProducesResponseType(typeof(ErrorMessageResponse), 410)]
|
||||
public ValueTask<IActionResult> Read([FromQuery] ulong? profileMs, CancellationToken cancellationToken) => ReadImpl(null, profileMs, false, cancellationToken);
|
||||
public ValueTask<IActionResult> Read(CancellationToken cancellationToken) => ReadImpl(null, false, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Stops the Watchdog if it's running.
|
||||
@@ -253,7 +252,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
else if ((oldSoftRestart && model.SoftRestart == false) || (oldSoftShutdown && model.SoftShutdown == false))
|
||||
await watchdog.ResetRebootState(cancellationToken);
|
||||
|
||||
return await ReadImpl(current, null, rebootRequired, cancellationToken);
|
||||
return await ReadImpl(current, rebootRequired, cancellationToken);
|
||||
});
|
||||
}
|
||||
#pragma warning restore CA1506
|
||||
@@ -312,25 +311,19 @@ namespace Tgstation.Server.Host.Controllers
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="Read(ulong?, CancellationToken)"/>.
|
||||
/// Implementation of <see cref="Read(CancellationToken)"/>.
|
||||
/// </summary>
|
||||
/// <param name="settings">The <see cref="DreamDaemonSettings"/> to operate on if any.</param>
|
||||
/// <param name="profileMs">The amount of time to spend profiling game server CPU performance.</param>
|
||||
/// <param name="knownForcedReboot">If there was a settings change made that forced a switch to <see cref="RebootState.Restart"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation.</returns>
|
||||
#pragma warning disable CA1502 // TODO: Decomplexify
|
||||
ValueTask<IActionResult> ReadImpl(DreamDaemonSettings? settings, ulong? profileMs, bool knownForcedReboot, CancellationToken cancellationToken)
|
||||
ValueTask<IActionResult> ReadImpl(DreamDaemonSettings? settings, bool knownForcedReboot, CancellationToken cancellationToken)
|
||||
#pragma warning restore CA1502
|
||||
=> WithComponentInstance(async instance =>
|
||||
{
|
||||
var dd = instance.Watchdog;
|
||||
var metadata = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (ulong)DreamDaemonRights.ReadMetadata) != 0;
|
||||
|
||||
Task<(long MemoryUsage, double CpuUsage)?>? profilingTask = null;
|
||||
if (metadata && profileMs.HasValue && dd.Status == WatchdogStatus.Online)
|
||||
profilingTask = dd.PerformanceProfile(TimeSpan.FromMilliseconds(profileMs.Value), cancellationToken);
|
||||
|
||||
var revision = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (ulong)DreamDaemonRights.ReadRevision) != 0;
|
||||
|
||||
if (settings == null)
|
||||
@@ -380,6 +373,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
result.Visibility = settings.Visibility!.Value;
|
||||
result.SoftRestart = rstate == RebootState.Restart;
|
||||
result.SoftShutdown = rstate == RebootState.Shutdown;
|
||||
result.ImmediateMemoryUsage = dd.MemoryUsage;
|
||||
|
||||
if (rstate == RebootState.Normal && knownForcedReboot)
|
||||
result.SoftRestart = true;
|
||||
@@ -393,16 +387,6 @@ namespace Tgstation.Server.Host.Controllers
|
||||
result.LogOutput = settings.LogOutput;
|
||||
result.MapThreads = settings.MapThreads;
|
||||
result.Minidumps = settings.Minidumps;
|
||||
|
||||
if (profilingTask != null)
|
||||
{
|
||||
var profile = await profilingTask;
|
||||
if (profile.HasValue)
|
||||
{
|
||||
result.ImmediateMemoryUsage = profile.Value.MemoryUsage;
|
||||
result.ImmediateCpuUsage = profile.Value.CpuUsage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (revision)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tgstation.Server.Host.System
|
||||
@@ -19,14 +18,6 @@ namespace Tgstation.Server.Host.System
|
||||
/// </summary>
|
||||
long MemoryUsage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Measures the <see cref="IProcessBase"/>'s CPU use percentage over a period of time.
|
||||
/// </summary>
|
||||
/// <param name="waitingWindow">The <see cref="TimeSpan"/> to measure the percentage over.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="double"/> ranging from 0-1 representing the percentage of the process' CPU time that was measured.</returns>
|
||||
ValueTask<double> GetCpuUsage(TimeSpan waitingWindow, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Set's the owned <see cref="global::System.Diagnostics.Process.PriorityClass"/> to a non-normal value.
|
||||
/// </summary>
|
||||
|
||||
@@ -7,7 +7,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
using Tgstation.Server.Host.IO;
|
||||
using Tgstation.Server.Host.Utils;
|
||||
|
||||
namespace Tgstation.Server.Host.System
|
||||
{
|
||||
@@ -31,11 +30,6 @@ namespace Tgstation.Server.Host.System
|
||||
/// </summary>
|
||||
readonly IProcessFeatures processFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IAsyncDelayer"/> for the <see cref="Process"/>.
|
||||
/// </summary>
|
||||
readonly IAsyncDelayer asyncDelayer;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ILogger"/> for the <see cref="Process"/>.
|
||||
/// </summary>
|
||||
@@ -71,7 +65,6 @@ namespace Tgstation.Server.Host.System
|
||||
/// Initializes a new instance of the <see cref="Process"/> class.
|
||||
/// </summary>
|
||||
/// <param name="processFeatures">The value of <see cref="processFeatures"/>.</param>
|
||||
/// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
|
||||
/// <param name="handle">The value of <see cref="handle"/>.</param>
|
||||
/// <param name="readerCts">The override value of <see cref="cancellationTokenSource"/>.</param>
|
||||
/// <param name="readTask">The value of <see cref="readTask"/>.</param>
|
||||
@@ -79,7 +72,6 @@ namespace Tgstation.Server.Host.System
|
||||
/// <param name="preExisting">If <paramref name="handle"/> was NOT just created.</param>
|
||||
public Process(
|
||||
IProcessFeatures processFeatures,
|
||||
IAsyncDelayer asyncDelayer,
|
||||
global::System.Diagnostics.Process handle,
|
||||
CancellationTokenSource? readerCts,
|
||||
Task<string?>? readTask,
|
||||
@@ -95,7 +87,6 @@ namespace Tgstation.Server.Host.System
|
||||
cancellationTokenSource = readerCts ?? new CancellationTokenSource();
|
||||
|
||||
this.processFeatures = processFeatures ?? throw new ArgumentNullException(nameof(processFeatures));
|
||||
this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
|
||||
|
||||
this.readTask = readTask;
|
||||
|
||||
@@ -245,24 +236,6 @@ namespace Tgstation.Server.Host.System
|
||||
return processFeatures.CreateDump(handle, outputFile, minidump, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<double> GetCpuUsage(TimeSpan waitingWindow, CancellationToken cancellationToken)
|
||||
{
|
||||
var startCpuUsage = handle.TotalProcessorTime;
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
await asyncDelayer.Delay(waitingWindow, cancellationToken);
|
||||
|
||||
var endCpuUsage = handle.TotalProcessorTime;
|
||||
var totalElapsedTime = stopwatch.Elapsed;
|
||||
|
||||
var cpuUsedMs = (endCpuUsage - startCpuUsage).TotalMilliseconds;
|
||||
var totalMsPassed = totalElapsedTime.TotalMilliseconds;
|
||||
|
||||
var cpuUsageTotal = cpuUsedMs / (Environment.ProcessorCount * totalMsPassed);
|
||||
|
||||
return cpuUsageTotal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches a log message to the process' exit event.
|
||||
/// </summary>
|
||||
|
||||
@@ -11,7 +11,6 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Tgstation.Server.Host.IO;
|
||||
using Tgstation.Server.Host.Utils;
|
||||
|
||||
namespace Tgstation.Server.Host.System
|
||||
{
|
||||
@@ -33,11 +32,6 @@ namespace Tgstation.Server.Host.System
|
||||
/// </summary>
|
||||
readonly IIOManager ioManager;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IAsyncDelayer"/> for the <see cref="ProcessExecutor"/>.
|
||||
/// </summary>
|
||||
readonly IAsyncDelayer asyncDelayer;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ILogger"/> for the <see cref="ProcessExecutor"/>.
|
||||
/// </summary>
|
||||
@@ -70,19 +64,16 @@ namespace Tgstation.Server.Host.System
|
||||
/// </summary>
|
||||
/// <param name="processFeatures">The value of <see cref="processFeatures"/>.</param>
|
||||
/// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
|
||||
/// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
|
||||
/// <param name="logger">The value of <see cref="logger"/>.</param>
|
||||
/// <param name="loggerFactory">The value of <see cref="loggerFactory"/>.</param>
|
||||
public ProcessExecutor(
|
||||
IProcessFeatures processFeatures,
|
||||
IIOManager ioManager,
|
||||
IAsyncDelayer asyncDelayer,
|
||||
ILogger<ProcessExecutor> logger,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.processFeatures = processFeatures ?? throw new ArgumentNullException(nameof(processFeatures));
|
||||
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
|
||||
this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
|
||||
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
|
||||
}
|
||||
@@ -204,7 +195,6 @@ namespace Tgstation.Server.Host.System
|
||||
|
||||
var process = new Process(
|
||||
processFeatures,
|
||||
asyncDelayer,
|
||||
handle,
|
||||
disposeCts,
|
||||
readTask,
|
||||
@@ -364,7 +354,6 @@ namespace Tgstation.Server.Host.System
|
||||
var pid = handle.Id;
|
||||
return new Process(
|
||||
processFeatures,
|
||||
asyncDelayer,
|
||||
handle,
|
||||
null,
|
||||
null,
|
||||
|
||||
@@ -61,7 +61,6 @@ namespace Tgstation.Server.Host.System.Tests
|
||||
new DefaultIOManager(),
|
||||
loggerFactory.CreateLogger<PosixProcessFeatures>()),
|
||||
Mock.Of<IIOManager>(),
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
loggerFactory.CreateLogger<ProcessExecutor>(),
|
||||
loggerFactory);
|
||||
await using var subProc = await processExecutor
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
async Task TestVisibilityPermission(CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedDD = await dreamDaemonClient.Read(null, cancellationToken);
|
||||
var updatedDD = await dreamDaemonClient.Read(cancellationToken);
|
||||
Assert.AreEqual(DreamDaemonVisibility.Public, updatedDD.Visibility);
|
||||
updatedDD = await dreamDaemonClient.Update(new DreamDaemonRequest
|
||||
{
|
||||
|
||||
@@ -150,7 +150,6 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
}, cancellationToken);
|
||||
|
||||
Assert.AreEqual<ushort?>(47, updated.OpenDreamTopicPort);
|
||||
Assert.IsFalse(updated.ImmediateCpuUsage.HasValue);
|
||||
Assert.IsFalse(updated.ImmediateMemoryUsage.HasValue);
|
||||
}
|
||||
catch (ConflictException ex) when (ex.ErrorCode == ErrorCode.PortNotAvailable)
|
||||
@@ -268,7 +267,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
do
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), tempToken);
|
||||
currentStatus = await instanceClient.DreamDaemon.Read(null, tempToken);
|
||||
currentStatus = await instanceClient.DreamDaemon.Read(tempToken);
|
||||
}
|
||||
while (currentStatus.Status != WatchdogStatus.Offline);
|
||||
}
|
||||
@@ -360,7 +359,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
// This one fucks with the access_identifer, run it in isolation
|
||||
await WhiteBoxValidateBridgeRequestLimitAndTestChunking(cancellationToken);
|
||||
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
await CheckDMApiFail(ddInfo.ActiveCompileJob, cancellationToken);
|
||||
|
||||
var deleteJob = await deleteJobTask;
|
||||
@@ -615,7 +614,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
await WaitForJob(startJob, 40, false, null, cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
|
||||
Assert.AreEqual(WatchdogStatus.Online, daemonStatus.Status.Value);
|
||||
ValidateSessionId(daemonStatus, true);
|
||||
@@ -716,19 +715,19 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
await WaitForJob(startJob, 40, false, null, cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
|
||||
Assert.AreEqual(WatchdogStatus.Online, daemonStatus.Status.Value);
|
||||
ValidateSessionId(daemonStatus, true);
|
||||
await CheckDDPriority();
|
||||
Assert.AreEqual(false, daemonStatus.SoftRestart);
|
||||
Assert.AreEqual(false, daemonStatus.SoftShutdown);
|
||||
Assert.IsFalse(daemonStatus.ImmediateMemoryUsage.HasValue);
|
||||
Assert.IsFalse(daemonStatus.ImmediateCpuUsage.HasValue);
|
||||
Assert.IsTrue(daemonStatus.ImmediateMemoryUsage.HasValue);
|
||||
Assert.AreNotEqual(0, daemonStatus.ImmediateMemoryUsage.Value);
|
||||
|
||||
await GracefulWatchdogShutdown(cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Offline, daemonStatus.Status.Value);
|
||||
Assert.IsFalse(daemonStatus.SessionId.HasValue);
|
||||
await ExpectGameDirectoryCount(1, cancellationToken);
|
||||
@@ -849,7 +848,6 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
? new WindowsProcessFeatures(Mock.Of<ILogger<WindowsProcessFeatures>>())
|
||||
: new PosixProcessFeatures(new Lazy<IProcessExecutor>(() => executor), new DefaultIOManager(), Mock.Of<ILogger<PosixProcessFeatures>>()),
|
||||
Mock.Of<IIOManager>(),
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
Mock.Of<ILogger<ProcessExecutor>>(),
|
||||
LoggerFactory.Create(x => { }));
|
||||
await using var ourProcessHandler = executor
|
||||
@@ -899,7 +897,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
var timeout = 20;
|
||||
do
|
||||
{
|
||||
ddStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
ddStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(1U, ddStatus.HealthCheckSeconds.Value);
|
||||
if (ddStatus.Status.Value == WatchdogStatus.Offline)
|
||||
{
|
||||
@@ -1119,11 +1117,11 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
// - Injects a custom bridge handler into the bridge registrar and makes the test hack into the DMAPI and change its access_identifier
|
||||
async Task WhiteBoxChatCommandTest(CancellationToken cancellationToken)
|
||||
{
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
for (int i = 0; ddInfo.Status != WatchdogStatus.Online && i < 15; ++i)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
|
||||
ddInfo = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
ddInfo = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
}
|
||||
|
||||
Assert.AreEqual(WatchdogStatus.Online, ddInfo.Status);
|
||||
@@ -1174,7 +1172,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
var endTime = DateTimeOffset.UtcNow + TimeSpan.FromSeconds(5);
|
||||
|
||||
ddInfo = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
ddInfo = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
await CheckDMApiFail(ddInfo.ActiveCompileJob, cancellationToken);
|
||||
|
||||
CheckEmbedsTest(embedsResponse, startTime, endTime);
|
||||
@@ -1275,7 +1273,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
await instanceClient.DreamDaemon.Shutdown(cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Offline, daemonStatus.Status.Value);
|
||||
await CheckDMApiFail(daemonStatus.ActiveCompileJob, cancellationToken);
|
||||
}
|
||||
@@ -1322,7 +1320,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
await instanceClient.DreamDaemon.Shutdown(cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Offline, daemonStatus.Status.Value);
|
||||
await CheckDMApiFail(daemonStatus.ActiveCompileJob, cancellationToken);
|
||||
}
|
||||
@@ -1335,7 +1333,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
var currentByondVersion = await instanceClient.Engine.ActiveVersion(cancellationToken);
|
||||
Assert.AreNotEqual(versionToInstall, currentByondVersion.EngineVersion);
|
||||
|
||||
var initialStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var initialStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
|
||||
var startJob = await StartDD(cancellationToken);
|
||||
|
||||
@@ -1365,15 +1363,12 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
|
||||
await DeployTestDme(DmeName, DreamDaemonSecurity.Safe, true, cancellationToken);
|
||||
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(500, cancellationToken);
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Online, daemonStatus.Status.Value);
|
||||
Assert.IsNotNull(daemonStatus.ActiveCompileJob);
|
||||
ValidateSessionId(daemonStatus, true);
|
||||
|
||||
Assert.IsTrue(daemonStatus.ImmediateCpuUsage.HasValue);
|
||||
Assert.IsTrue(daemonStatus.ImmediateMemoryUsage.HasValue);
|
||||
|
||||
// Assert.AreNotEqual(0, daemonStatus.ImmediateCpuUsage.Value); sleep_offline cucks this check
|
||||
Assert.AreNotEqual(0, daemonStatus.ImmediateMemoryUsage.Value);
|
||||
|
||||
Assert.AreEqual(initialStatus.ActiveCompileJob.Id, daemonStatus.ActiveCompileJob.Id);
|
||||
@@ -1394,7 +1389,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
await instanceClient.DreamDaemon.Shutdown(cancellationToken);
|
||||
await CheckDMApiFail(daemonStatus.ActiveCompileJob, cancellationToken);
|
||||
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Offline, daemonStatus.Status.Value);
|
||||
}
|
||||
|
||||
@@ -1427,7 +1422,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
KillDD(firstTime);
|
||||
firstTime = false;
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
}
|
||||
while (daemonStatus.Status == WatchdogStatus.Online);
|
||||
Assert.AreEqual(WatchdogStatus.Restoring, daemonStatus.Status);
|
||||
@@ -1436,7 +1431,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
do
|
||||
{
|
||||
KillDD(false);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
}
|
||||
while (daemonStatus.Status == WatchdogStatus.Online || daemonStatus.Status == WatchdogStatus.Restoring);
|
||||
Assert.AreEqual(WatchdogStatus.DelayedRestart, daemonStatus.Status);
|
||||
@@ -1471,7 +1466,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
=> TellWorldToReboot2(instanceClient, instanceManager, topicClient, FindTopicPort(), waitForOnlineIfRestoring || testVersion.Engine.Value == EngineType.OpenDream, cancellationToken, source);
|
||||
public static async Task<DreamDaemonResponse> TellWorldToReboot2(IInstanceClient instanceClient, IInstanceManager instanceManager, ITopicClient topicClient, ushort topicPort, bool waitForOnlineIfRestoring, CancellationToken cancellationToken, [CallerLineNumber]int source = 0, [CallerFilePath]string path = null)
|
||||
{
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.IsNotNull(daemonStatus.StagedCompileJob);
|
||||
var initialSession = daemonStatus.ActiveCompileJob;
|
||||
|
||||
@@ -1489,7 +1484,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
do
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), tempToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, tempToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(tempToken);
|
||||
}
|
||||
while (initialSession.Id == daemonStatus.ActiveCompileJob.Id);
|
||||
}
|
||||
@@ -1499,7 +1494,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
do
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), tempToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(null, tempToken);
|
||||
daemonStatus = await instanceClient.DreamDaemon.Read(tempToken);
|
||||
}
|
||||
while (daemonStatus.Status == WatchdogStatus.Restoring);
|
||||
}
|
||||
@@ -1542,7 +1537,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
for (var i = 0; i < 10; ++i)
|
||||
await Task.Yield();
|
||||
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var ddInfo = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
var targetJob = ddInfo.StagedCompileJob ?? ddInfo.ActiveCompileJob;
|
||||
Assert.IsNotNull(targetJob);
|
||||
if (requireApi)
|
||||
@@ -1560,14 +1555,14 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
SoftShutdown = true
|
||||
}, cancellationToken);
|
||||
|
||||
var newStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var newStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.IsTrue(newStatus.SoftShutdown.Value || newStatus.Status.Value == WatchdogStatus.Offline);
|
||||
|
||||
var timeout = 40;
|
||||
do
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
|
||||
var ddStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var ddStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
if (ddStatus.Status.Value == WatchdogStatus.Offline)
|
||||
break;
|
||||
|
||||
@@ -1595,7 +1590,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
if (!checkLogs)
|
||||
return;
|
||||
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
if (daemonStatus.Status != WatchdogStatus.Offline || !daemonStatus.LogOutput.Value)
|
||||
return;
|
||||
|
||||
@@ -1618,7 +1613,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
cancellationToken);
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual("all gucci", result.StringData);
|
||||
await CheckDMApiFail((await instanceClient.DreamDaemon.Read(null, cancellationToken)).ActiveCompileJob, cancellationToken);
|
||||
await CheckDMApiFail((await instanceClient.DreamDaemon.Read(cancellationToken)).ActiveCompileJob, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,7 +1095,6 @@ namespace Tgstation.Server.Tests.Live
|
||||
? new WindowsProcessFeatures(loggerFactory.CreateLogger<WindowsProcessFeatures>())
|
||||
: new PosixProcessFeatures(new Lazy<IProcessExecutor>(() => processExecutor), ioManager, loggerFactory.CreateLogger<PosixProcessFeatures>()),
|
||||
ioManager,
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
loggerFactory.CreateLogger<ProcessExecutor>(),
|
||||
loggerFactory);
|
||||
|
||||
@@ -1198,7 +1197,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
|
||||
|
||||
var status = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var status = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
|
||||
if (updated)
|
||||
{
|
||||
@@ -1546,7 +1545,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
if (openDreamOnly)
|
||||
return;
|
||||
|
||||
var dd = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var dd = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Online, dd.Status.Value);
|
||||
Assert.IsNotNull(dd.StagedCompileJob);
|
||||
Assert.AreNotEqual(dd.StagedCompileJob.Id, dd.ActiveCompileJob.Id);
|
||||
@@ -1629,7 +1628,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
await jrt.WaitForJob(job, 130, job.Description.Contains("Reconnect chat bot") ? null : false, null, cancellationToken);
|
||||
}
|
||||
|
||||
var dd = await instanceClient.DreamDaemon.Read(500, cancellationToken);
|
||||
var dd = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(WatchdogStatus.Online, dd.Status.Value);
|
||||
Assert.IsNotNull(dd.StagedCompileJob);
|
||||
Assert.AreNotEqual(dd.StagedCompileJob.Id, dd.ActiveCompileJob.Id);
|
||||
@@ -1713,7 +1712,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
var instanceClient = adminClient.Instances.CreateClient(instance);
|
||||
await WaitForInitialJobs(instanceClient);
|
||||
|
||||
var dd = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var dd = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
|
||||
Assert.AreEqual(WatchdogStatus.Online, dd.Status.Value);
|
||||
|
||||
@@ -1721,7 +1720,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
await using var wdt = new WatchdogTest(edgeVersion, instanceClient, GetInstanceManager(), (ushort)server.ApiUrl.Port, server.HighPriorityDreamDaemon, mainDDPort.Value, server.UsingBasicWatchdog);
|
||||
await wdt.WaitForJob(compileJob, 30, false, null, cancellationToken);
|
||||
|
||||
dd = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
dd = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(dd.StagedCompileJob.Job.Id, compileJob.Id);
|
||||
|
||||
expectedCompileJobId = compileJob.Id.Value;
|
||||
@@ -1756,7 +1755,7 @@ namespace Tgstation.Server.Tests.Live
|
||||
var instanceClient = adminClient.Instances.CreateClient(instance);
|
||||
await WaitForInitialJobs(instanceClient);
|
||||
|
||||
var currentDD = await instanceClient.DreamDaemon.Read(null, cancellationToken);
|
||||
var currentDD = await instanceClient.DreamDaemon.Read(cancellationToken);
|
||||
Assert.AreEqual(expectedCompileJobId, currentDD.ActiveCompileJob.Id.Value);
|
||||
Assert.AreEqual(WatchdogStatus.Online, currentDD.Status);
|
||||
Assert.AreEqual(expectedStaged, currentDD.StagedCompileJob.Job.Id.Value);
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace Tgstation.Server.Tests
|
||||
var processExecutor = new ProcessExecutor(
|
||||
Mock.Of<IProcessFeatures>(),
|
||||
new DefaultIOManager(),
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
Mock.Of<ILogger<ProcessExecutor>>(),
|
||||
loggerFactory);
|
||||
|
||||
@@ -54,7 +53,6 @@ namespace Tgstation.Server.Tests
|
||||
var processExecutor = new ProcessExecutor(
|
||||
Mock.Of<IProcessFeatures>(),
|
||||
new DefaultIOManager(),
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
loggerFactory.CreateLogger<ProcessExecutor>(),
|
||||
loggerFactory);
|
||||
|
||||
|
||||
@@ -211,7 +211,6 @@ namespace Tgstation.Server.Tests
|
||||
new DefaultIOManager(),
|
||||
loggerFactory.CreateLogger<PosixProcessFeatures>()),
|
||||
Mock.Of<IIOManager>(),
|
||||
Mock.Of<IAsyncDelayer>(),
|
||||
loggerFactory.CreateLogger<ProcessExecutor>(),
|
||||
loggerFactory);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user