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.
52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Instance;
|
|
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
|
|
|
|
public class AttributeSchedulerRegressionTests : TestKit
|
|
{
|
|
/// <summary>Verifies that saturated workers complete synchronous attribute access without tripping the watchdog.</summary>
|
|
/// <param name="write">The write.</param>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public async Task SR1_SaturatedWorkersCompleteSynchronousAccessWithoutWatchdog(bool write)
|
|
{
|
|
const int workers = 2;
|
|
using var scheduler = new ScriptExecutionScheduler(workers);
|
|
var probe = CreateTestProbe();
|
|
var context = new ScriptRuntimeContext(probe.Ref, null!, 0, 10, TimeSpan.FromSeconds(3),
|
|
"Pump", NullLogger<ScriptRuntimeContext>.Instance);
|
|
var accessor = new AttributeAccessor(context, "");
|
|
var tasks = Enumerable.Range(0, workers).Select(_ => Task.Factory.StartNew(() =>
|
|
{
|
|
if (write) accessor["x"] = 42;
|
|
else Assert.Equal(42, accessor["x"]);
|
|
}, CancellationToken.None, TaskCreationOptions.None, scheduler)).ToArray();
|
|
|
|
// Hold both replies until every worker is blocked inside the synchronous accessor.
|
|
var replies = new List<(IActorRef Sender, object Response)>();
|
|
for (var i = 0; i < workers; i++)
|
|
{
|
|
if (write)
|
|
{
|
|
var request = probe.ExpectMsg<SetStaticAttributeCommand>();
|
|
replies.Add((probe.LastSender, new SetStaticAttributeResponse(request.CorrelationId,
|
|
"Pump", "x", true, null, DateTimeOffset.UtcNow)));
|
|
}
|
|
else
|
|
{
|
|
var request = probe.ExpectMsg<GetAttributeRequest>();
|
|
replies.Add((probe.LastSender, new GetAttributeResponse(request.CorrelationId,
|
|
"Pump", "x", 42, true, "Good", DateTimeOffset.UtcNow)));
|
|
}
|
|
}
|
|
foreach (var reply in replies) reply.Sender.Tell(reply.Response);
|
|
await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromSeconds(2));
|
|
}
|
|
}
|