6004a5a565
1. A post-dispatch refusal now puts the node back to its captured pre-call state with one corrective event (skipped when the node changed since) — the SDK had already applied and reported the change. Blank scripted AddComment is refused in the handler before the SDK runs. 2. ScriptedAlarmCommandDispatch: ask the local engine first, broadcast to the peer only on Applied/OutcomeUnknown — a refusal now reached no engine anywhere. 3. ApplyAsync no longer checks 'loaded' before _evalGate: a command racing the first load queues behind it; never loaded => refusal (nothing applied). 4. One Call's requests are settled sequentially (no request runs against a node state the engine refused); <= 64 asks in flight node-wide, else BadTooManyOperations before anything applies; per-request bound starts at send. Measured 300 acks through one host + LocalDb: 59 ms sequential, max 24 ms/ask with 64 outstanding. 5. Mixed-batch wire test (scripted refused + native + imported + scripted applied + core-manager method): per-item status in order, one scripted ask at a time. L6: readiness from the engine's HasCompleteGeneration on a load fault. L7: the verdict slot is closed when its SDK call returns (timer-captured AsyncLocal can no longer park an ask). L10: remote budget never stretched. Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
2.7 KiB
C#
54 lines
2.7 KiB
C#
using Akka.Actor;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
|
using ZB.MOM.WW.OtOpcUa.Host.OpcUa;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Host.Tests.OpcUa;
|
|
|
|
/// <summary>
|
|
/// #937 review r1: the redundant peer receives a Part 9 command only after THIS node's engine applied it (or did not
|
|
/// answer) — a local refusal must reach no engine anywhere, or the caller's definite failure and the node revert lie.
|
|
/// </summary>
|
|
public sealed class ScriptedAlarmCommandDispatchTests
|
|
{
|
|
private static readonly AlarmCommand Cmd = new("alm-1", "Acknowledge", "alice", null, null, "cmd-1");
|
|
|
|
[Theory]
|
|
[InlineData(AlarmCommandVerdict.Applied, true)]
|
|
[InlineData(AlarmCommandVerdict.OutcomeUnknown, true)]
|
|
[InlineData(AlarmCommandVerdict.NotApplied, false)]
|
|
public async Task The_peer_broadcast_follows_the_local_verdict(AlarmCommandVerdict verdict, bool broadcast)
|
|
{
|
|
var order = new List<string>();
|
|
var outcome = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromSeconds(1),
|
|
(c, _) => { order.Add("ask"); return Task.FromResult(new AlarmCommandOutcome(c.AlarmId, c.Operation, verdict)); },
|
|
c => order.Add("broadcast:" + c.CommandId), NullLogger.Instance);
|
|
|
|
outcome.Verdict.ShouldBe(verdict);
|
|
order.ShouldBe(broadcast ? ["ask", "broadcast:cmd-1"] : ["ask"]);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task No_answer_is_outcome_unknown_and_still_broadcast_and_no_engine_is_a_refusal_with_none()
|
|
{
|
|
var sent = 0;
|
|
var timedOut = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromMilliseconds(10),
|
|
(_, _) => Task.FromException<AlarmCommandOutcome>(new AskTimeoutException("no answer")), _ => sent++, NullLogger.Instance);
|
|
timedOut.Verdict.ShouldBe(AlarmCommandVerdict.OutcomeUnknown);
|
|
timedOut.TimedOut.ShouldBeTrue();
|
|
sent.ShouldBe(1, "the local engine may still apply it, so the peer must not be left behind");
|
|
|
|
var none = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromSeconds(1), null, _ => sent++, NullLogger.Instance);
|
|
none.Verdict.ShouldBe(AlarmCommandVerdict.NotApplied);
|
|
sent.ShouldBe(1);
|
|
|
|
// A failing broadcast never changes the caller's answer.
|
|
var applied = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromSeconds(1),
|
|
(c, _) => Task.FromResult(new AlarmCommandOutcome(c.AlarmId, c.Operation, AlarmCommandVerdict.Applied)),
|
|
_ => throw new InvalidOperationException("mediator down"), NullLogger.Instance);
|
|
applied.Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
|
}
|
|
}
|