513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
|
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
|
|
|
|
/// <summary>
|
|
/// SiteRuntime-S2/UA5: the hosted reporter must lift the process-wide
|
|
/// <see cref="ScriptExecutionScheduler"/> gauges onto the site health report via
|
|
/// <see cref="ISiteHealthCollector"/>. Uses the real collector (NSubstitute is not
|
|
/// referenced by this test project) and drives the shared scheduler busy so the
|
|
/// pushed value is distinguishable from the idle default.
|
|
/// </summary>
|
|
public class ScriptSchedulerStatsReporterTests
|
|
{
|
|
/// <summary>Verifies that the reporter pushes the scheduler statistics to the health collector.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Reporter_PushesSchedulerStatsToCollector()
|
|
{
|
|
var options = new SiteRuntimeOptions { ScriptExecutionThreadCount = 1 };
|
|
var collector = new SiteHealthCollector();
|
|
var scheduler = ScriptExecutionScheduler.Shared(options);
|
|
|
|
using var gate = new ManualResetEventSlim(false);
|
|
// Occupy a worker thread so BusyThreadCount is a non-zero, distinguishable value.
|
|
var blocking = Task.Factory.StartNew(() => gate.Wait(),
|
|
CancellationToken.None, TaskCreationOptions.None, scheduler);
|
|
await WaitUntilAsync(() => scheduler.BusyThreadCount >= 1);
|
|
|
|
using var reporter = new ScriptSchedulerStatsReporter(
|
|
collector, options, NullLogger<ScriptSchedulerStatsReporter>.Instance,
|
|
pollInterval: TimeSpan.FromMilliseconds(50));
|
|
|
|
await reporter.StartAsync(CancellationToken.None);
|
|
try
|
|
{
|
|
await WaitUntilAsync(() => collector.CollectReport("site-1").ScriptBusyThreads >= 1);
|
|
var report = collector.CollectReport("site-1");
|
|
Assert.True(report.ScriptBusyThreads >= 1);
|
|
Assert.NotNull(report.ScriptOldestBusyAgeSeconds); // a script is in flight
|
|
}
|
|
finally
|
|
{
|
|
gate.Set();
|
|
await blocking;
|
|
await reporter.StopAsync(CancellationToken.None);
|
|
}
|
|
}
|
|
|
|
private static async Task WaitUntilAsync(Func<bool> condition)
|
|
{
|
|
for (var i = 0; i < 100 && !condition(); i++)
|
|
await Task.Delay(50);
|
|
Assert.True(condition(), "condition not met within timeout");
|
|
}
|
|
}
|