fix(alarms): #951 #952 #953 — late refusal reverts, never-started command is NotApplied, superseded load failure ignored
#951: the hosted-service Ask lives LateVerdictWindow (30 s) past the caller's bound (ExecuteAlarmCommand deadline unchanged); the OutcomeUnknown it returns carries the still-running ask as AlarmCommandOutcome.LateOutcome (process-local). The node manager watches it (or the asker task itself when its backstop expired, following unknown chains) and reverts the node on a late NotApplied, under the existing per-condition mutation-counter guard. Both CallAsync and remote ExecuteConditionMethodAsync paths. #952: ScriptedAlarmEngine throws ScriptedAlarmCommandNotStartedException (an OCE) when a command is cancelled before it acquires _evalGate; a cancellation inside SaveAsync stays a plain OCE (unknown). The host maps not-started to NotApplied and remembers it, except on the direct ask once its asker's deadline passed (asker already answered unknown and broadcast): then unknown + not remembered, so the broadcast copy decides (as review r2 M2). #953: a faulted load pipes back AlarmsLoadFailed(cause, generation); a failure from a generation a newer apply superseded publishes no readiness (it would refuse every command while the newer load is in flight). Red/green: each fix reverted individually turns its tests red (Core 1, Runtime 3, Host 1, OpcUaServer.IntegrationTests 4). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -50,4 +50,34 @@ public sealed class ScriptedAlarmCommandDispatchTests
|
||||
_ => throw new InvalidOperationException("mediator down"), NullLogger.Instance);
|
||||
applied.Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #951: the caller's bound expiring does not drop the host's answer — the OutcomeUnknown carries the still-running ask
|
||||
/// as its <see cref="AlarmCommandOutcome.LateOutcome"/>, so a refusal that arrives later can still revert the node.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task An_answer_after_the_bound_rides_the_unknown_outcome_as_its_late_outcome()
|
||||
{
|
||||
var sent = 0;
|
||||
var host = new TaskCompletionSource<AlarmCommandOutcome>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
TimeSpan? askedBound = null;
|
||||
var unknown = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromMilliseconds(50),
|
||||
(_, bound) => { askedBound = bound; return host.Task; }, _ => sent++, NullLogger.Instance);
|
||||
|
||||
askedBound.ShouldBe(TimeSpan.FromMilliseconds(50), "the host's deadline is still the caller's bound");
|
||||
unknown.Verdict.ShouldBe(AlarmCommandVerdict.OutcomeUnknown);
|
||||
unknown.TimedOut.ShouldBeTrue();
|
||||
sent.ShouldBe(1);
|
||||
var late = unknown.LateOutcome;
|
||||
(late is not null).ShouldBeTrue("the host's answer is still collected");
|
||||
late!.IsCompleted.ShouldBeFalse();
|
||||
|
||||
host.SetResult(new AlarmCommandOutcome(Cmd.AlarmId, Cmd.Operation, AlarmCommandVerdict.NotApplied, "load failed"));
|
||||
(await late).Verdict.ShouldBe(AlarmCommandVerdict.NotApplied);
|
||||
|
||||
// An ask that FAILED inside the bound has no later answer.
|
||||
var faulted = await ScriptedAlarmCommandDispatch.AskThenBroadcastAsync(Cmd, TimeSpan.FromSeconds(1),
|
||||
(_, _) => Task.FromException<AlarmCommandOutcome>(new AskTimeoutException("no answer")), _ => sent++, NullLogger.Instance);
|
||||
(faulted.LateOutcome is null).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+123
@@ -419,4 +419,127 @@ public sealed class ScriptedCommandVerdictWireTests
|
||||
}
|
||||
finally { await rig.DisposeAsync(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #951: the engine refuses AFTER the caller was told OutcomeUnknown (BadTimeout) — e.g. the command was queued behind a
|
||||
/// load that then failed. The node does not keep the SDK-applied change: the late refusal reverts it with exactly one
|
||||
/// corrective event, as an in-time refusal does. Covers both shapes of "late": the asker's own timeout outcome carrying
|
||||
/// the host's still-running answer, and an asker that never answered inside the node manager's backstop.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task A_refusal_arriving_after_the_timeout_reverts_the_node(bool viaLateOutcome)
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
var rig = await StartAsync($"Verdict951Late{viaLateOutcome}", encrypted: false, ct);
|
||||
try
|
||||
{
|
||||
rig.Enforce(false, [Key()], ClusterGrant(KeyPrincipal, "acl-key", All));
|
||||
rig.MaterialiseScripted();
|
||||
rig.Nm.ScriptedCommandTimeout = TimeSpan.FromMilliseconds(500);
|
||||
var host = new TaskCompletionSource<AlarmCommandOutcome>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
rig.Nm.AlarmCommandAsker = (cmd, _) => viaLateOutcome
|
||||
? Task.FromResult(new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation, AlarmCommandVerdict.OutcomeUnknown,
|
||||
"OutcomeUnknown: no answer in time", TimedOut: true) { LateOutcome = host.Task })
|
||||
: host.Task;
|
||||
|
||||
using var session = await rig.ConnectAsync(anonymous: false, ct);
|
||||
var events = new RecordedEvents();
|
||||
var subscription = await RecordedEvents.SubscribeAsync(session, events, ct);
|
||||
var item = RecordedEvents.AddEventItem(subscription, ObjectIds.Server);
|
||||
await subscription.ApplyChangesAsync(ct);
|
||||
rig.Project(false, ConditionMethodEventTests.PreState("Acknowledge", native: false) with { Message = "base" });
|
||||
await RecordedEvents.WaitUntilAsync(() => events.Has(item, "base"));
|
||||
|
||||
var unknown = await Should.ThrowAsync<ServiceResultException>(ConditionMethodEventTests.CallAsync(
|
||||
session, ConditionNodeId(session, false), "Acknowledge", events.LatestEventId(item, "base"), ct));
|
||||
unknown.StatusCode.ShouldBe(StatusCodes.BadTimeout);
|
||||
rig.Nm.TryGetAlarmCondition(ScriptedAlarmId)!.AckedState!.Id!.Value
|
||||
.ShouldBeTrue("an unknown outcome keeps the change — the engine may still apply it");
|
||||
|
||||
host.SetResult(new AlarmCommandOutcome(ScriptedAlarmId, "Acknowledge", AlarmCommandVerdict.NotApplied, "load failed"));
|
||||
await RecordedEvents.WaitUntilAsync(() => events.ConditionEvents(item, "base").Count >= 3);
|
||||
rig.Project(false, ConditionMethodEventTests.PreState("Acknowledge", native: false) with { Message = "sentinel" });
|
||||
await RecordedEvents.WaitUntilAsync(() => events.Has(item, "sentinel"));
|
||||
var baseEvents = events.ConditionEvents(item, "base");
|
||||
baseEvents.Count.ShouldBe(3, "the base transition, the method's event, and exactly one corrective event");
|
||||
baseEvents[2][RecordedEvents.AckedField].ClrValue().ShouldBe(baseEvents[0][RecordedEvents.AckedField].ClrValue());
|
||||
await subscription.DeleteAsync(true, ct);
|
||||
}
|
||||
finally { await rig.DisposeAsync(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #951: only a late REFUSAL reverts. A late answer already in when the verdict is settled is acted on before the call
|
||||
/// returns, so each arm is observed deterministically: Applied / still-unknown keep the change; NotApplied (here behind
|
||||
/// one more unknown hop, so the chain is followed) reverts it.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(AlarmCommandVerdict.Applied, false)]
|
||||
[InlineData(AlarmCommandVerdict.OutcomeUnknown, false)]
|
||||
[InlineData(AlarmCommandVerdict.NotApplied, true)]
|
||||
public async Task Only_a_late_refusal_reverts(AlarmCommandVerdict lateVerdict, bool reverted)
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
var rig = await StartAsync($"Verdict951Only{lateVerdict}", encrypted: false, ct);
|
||||
try
|
||||
{
|
||||
rig.Enforce(false, [Key()], ClusterGrant(KeyPrincipal, "acl-key", All));
|
||||
rig.MaterialiseScripted();
|
||||
rig.Nm.AlarmCommandAsker = (cmd, _) =>
|
||||
{
|
||||
var late = new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation, lateVerdict);
|
||||
if (lateVerdict == AlarmCommandVerdict.NotApplied)
|
||||
{
|
||||
late = new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation, AlarmCommandVerdict.OutcomeUnknown, "hop", TimedOut: true)
|
||||
{ LateOutcome = Task.FromResult(late) };
|
||||
}
|
||||
return Task.FromResult(new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation, AlarmCommandVerdict.OutcomeUnknown,
|
||||
"OutcomeUnknown: no answer in time", TimedOut: true) { LateOutcome = Task.FromResult(late) });
|
||||
};
|
||||
rig.Project(false, ConditionMethodEventTests.PreState("Acknowledge", native: false) with { Message = "base" });
|
||||
await rig.DrainProjectionsAsync();
|
||||
|
||||
using var session = await rig.ConnectAsync(anonymous: false, ct);
|
||||
var eventId = rig.Nm.TryGetAlarmCondition(ScriptedAlarmId)!.EventId!.Value;
|
||||
var result = await session.CallAsync(null, [new CallMethodRequest
|
||||
{
|
||||
ObjectId = ConditionNodeId(session, false), MethodId = MethodIds.AcknowledgeableConditionType_Acknowledge,
|
||||
InputArguments = [new Variant(eventId), new Variant(new LocalizedText("x"))],
|
||||
}], ct);
|
||||
result.Results[0].StatusCode.Code.ShouldBe(StatusCodes.BadTimeout.Code);
|
||||
rig.Nm.TryGetAlarmCondition(ScriptedAlarmId)!.AckedState!.Id!.Value.ShouldBe(!reverted);
|
||||
}
|
||||
finally { await rig.DisposeAsync(); }
|
||||
}
|
||||
|
||||
/// <summary>#951 for a remote (gRPC data) condition method: a refusal arriving after the Unknown answer reverts the node too.</summary>
|
||||
[Fact]
|
||||
public async Task A_remote_condition_method_refused_after_its_timeout_reverts_the_node()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
var rig = await StartAsync("Verdict951Remote", encrypted: false, ct);
|
||||
try
|
||||
{
|
||||
rig.MaterialiseScripted();
|
||||
rig.Project(false, ConditionMethodEventTests.PreState("Acknowledge", native: false) with { Message = "base" });
|
||||
await rig.DrainProjectionsAsync();
|
||||
var host = new TaskCompletionSource<AlarmCommandOutcome>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
rig.Nm.AlarmCommandAsker = (cmd, _) => Task.FromResult(new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation,
|
||||
AlarmCommandVerdict.OutcomeUnknown, "OutcomeUnknown: no answer in time", TimedOut: true) { LateOutcome = host.Task });
|
||||
|
||||
var marker = rig.Nm.SnapshotConditions((_, id) => id == ScriptedAlarmId, 10)
|
||||
.SelectMany(s => s.Records).Single(c => c.ConditionId == ScriptedAlarmId).Activation;
|
||||
var call = new OriginConditionMethodCall(AddressSpaceRealm.Uns, ScriptedAlarmId, "Acknowledge", "ack", marker, "svc", null);
|
||||
|
||||
var unknown = await rig.Nm.ExecuteConditionMethodAsync(call, TimeSpan.FromSeconds(5));
|
||||
unknown.Unknown.ShouldBeTrue();
|
||||
rig.Nm.TryGetAlarmCondition(ScriptedAlarmId)!.AckedState!.Id!.Value.ShouldBeTrue("unknown keeps the change");
|
||||
|
||||
host.SetResult(new AlarmCommandOutcome(ScriptedAlarmId, "Acknowledge", AlarmCommandVerdict.NotApplied, "load failed"));
|
||||
await RecordedEvents.WaitUntilAsync(() => !rig.Nm.TryGetAlarmCondition(ScriptedAlarmId)!.AckedState!.Id!.Value);
|
||||
}
|
||||
finally { await rig.DisposeAsync(); }
|
||||
}
|
||||
}
|
||||
|
||||
+156
-3
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Akka.Actor;
|
||||
using Akka.TestKit;
|
||||
using Serilog;
|
||||
@@ -29,18 +30,53 @@ public sealed class ScriptedAlarmCommandVerdictTests : RuntimeActorTestBase
|
||||
|
||||
private static EquipmentScriptedAlarmPlan BadPlan(string id) => Plan(id, "return unknownIdentifier;");
|
||||
|
||||
private (IActorRef Host, ScriptedAlarmEngine Engine, ScriptedAlarmCommandReadinessView Readiness, TestProbe Mux) Spawn()
|
||||
private (IActorRef Host, ScriptedAlarmEngine Engine, ScriptedAlarmCommandReadinessView Readiness, TestProbe Mux) Spawn(
|
||||
IAlarmStateStore? store = null, TimeSpan? commandTimeout = null)
|
||||
{
|
||||
var publish = CreateTestProbe();
|
||||
var mux = CreateTestProbe();
|
||||
var upstream = new DependencyMuxTagUpstreamSource();
|
||||
var logger = new LoggerConfiguration().CreateLogger();
|
||||
var engine = new ScriptedAlarmEngine(upstream, new InMemoryAlarmStateStore(), new ScriptLoggerFactory(logger), logger);
|
||||
var engine = new ScriptedAlarmEngine(upstream, store ?? new InMemoryAlarmStateStore(), new ScriptLoggerFactory(logger), logger);
|
||||
var readiness = new ScriptedAlarmCommandReadinessView();
|
||||
var host = Sys.ActorOf(ScriptedAlarmHostActor.Props(publish.Ref, mux.Ref, () => (upstream, engine), readiness: readiness));
|
||||
var host = Sys.ActorOf(ScriptedAlarmHostActor.Props(publish.Ref, mux.Ref, () => (upstream, engine),
|
||||
commandTimeout: commandTimeout, readiness: readiness));
|
||||
return (host, engine, readiness, mux);
|
||||
}
|
||||
|
||||
/// <summary>An in-memory store whose per-alarm row read (the engine does it under its gate, inside LoadAsync, for an alarm
|
||||
/// it carries no state for) can be held — so a load holds the engine's gate for exactly as long as the test says.</summary>
|
||||
private sealed class HoldableStore : IAlarmStateStore
|
||||
{
|
||||
private readonly InMemoryAlarmStateStore _inner = new();
|
||||
private readonly ConcurrentDictionary<string, (TaskCompletionSource Reached, TaskCompletionSource<Exception?> Release)> _holds =
|
||||
new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Holds the next read of <paramref name="alarmId"/>: <c>Reached</c> completes once it is held; completing
|
||||
/// <c>Release</c> with null answers the read, with an exception throws it.</summary>
|
||||
public (Task Reached, TaskCompletionSource<Exception?> Release) Hold(string alarmId)
|
||||
{
|
||||
var reached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var release = new TaskCompletionSource<Exception?>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
_holds[alarmId] = (reached, release);
|
||||
return (reached.Task, release);
|
||||
}
|
||||
|
||||
public async Task<AlarmConditionState?> LoadAsync(string alarmId, CancellationToken ct)
|
||||
{
|
||||
if (_holds.TryRemove(alarmId, out var hold))
|
||||
{
|
||||
hold.Reached.TrySetResult();
|
||||
if (await hold.Release.Task is { } fault) throw fault;
|
||||
}
|
||||
return await _inner.LoadAsync(alarmId, ct);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<AlarmConditionState>> LoadAllAsync(CancellationToken ct) => _inner.LoadAllAsync(ct);
|
||||
public Task SaveAsync(AlarmConditionState state, CancellationToken ct) => _inner.SaveAsync(state, ct);
|
||||
public Task RemoveAsync(string alarmId, CancellationToken ct) => _inner.RemoveAsync(alarmId, ct);
|
||||
}
|
||||
|
||||
private static Task<AlarmCommandOutcome> Ask(IActorRef host, string alarmId, string operation, string? comment = null, string? commandId = null) =>
|
||||
host.Ask<AlarmCommandOutcome>(new ScriptedAlarmHostActor.ExecuteAlarmCommand(
|
||||
new AlarmCommand(alarmId, operation, "alice", comment, null, commandId)), Timeout, Ct);
|
||||
@@ -133,4 +169,121 @@ public sealed class ScriptedAlarmCommandVerdictTests : RuntimeActorTestBase
|
||||
(await Ask(host, "alm-1", "AddComment", "other", "cmd-2")).Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
||||
engine.GetState("alm-1")!.Comments.Select(c => c.Text).ShouldBe(["note", "other"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #952: a command still waiting for the engine's gate when its bound expires (queued behind a load) was never started —
|
||||
/// a definite NotApplied, not OutcomeUnknown (which told the caller "may still apply", broadcast it to the peer and kept
|
||||
/// the node change). Remembered, so a broadcast copy of the same id is not applied afterwards (the refusal stays true).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_command_that_never_got_the_engine_gate_is_not_applied()
|
||||
{
|
||||
var store = new HoldableStore();
|
||||
var (host, engine, _, mux) = Spawn(store, commandTimeout: TimeSpan.FromMilliseconds(300));
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1")]));
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
|
||||
// A deploy adding alm-2 reads its row under the engine gate — held, so the gate stays taken.
|
||||
var (reached, release) = store.Hold("alm-2");
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1"), Plan("alm-2")]));
|
||||
await reached.WaitAsync(Timeout, Ct);
|
||||
|
||||
var refused = await Ask(host, "alm-1", "AddComment", "blocked", "cmd-blocked");
|
||||
refused.Verdict.ShouldBe(AlarmCommandVerdict.NotApplied);
|
||||
refused.Reason.ShouldBe(ScriptedAlarmHostActor.NotStartedRefusal);
|
||||
|
||||
release.SetResult(null);
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
host.Tell(new AlarmCommand("alm-1", "AddComment", "alice", "blocked", null, "cmd-blocked")); // its broadcast copy
|
||||
// Positive control behind it in the mailbox: the engine is free again, and the copy above was processed first.
|
||||
(await Ask(host, "alm-1", "AddComment", "after", "cmd-after")).Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
||||
engine.GetState("alm-1")!.Comments.Select(c => c.Text).ShouldBe(["after"], "the refused command was never applied");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #952: the same never-started command, but its asker's deadline passed while it waited — the asker already answered
|
||||
/// OutcomeUnknown and broadcast it, so (as for an ask that expired before it started, review r2 M2) it is answered
|
||||
/// unknown and NOT remembered: the broadcast copy decides here.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_never_started_command_past_its_asker_deadline_leaves_the_broadcast_copy_to_decide()
|
||||
{
|
||||
var store = new HoldableStore();
|
||||
var (host, engine, _, mux) = Spawn(store, commandTimeout: TimeSpan.FromSeconds(3));
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1")]));
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
|
||||
var (reached, release) = store.Hold("alm-2");
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1"), Plan("alm-2")]));
|
||||
await reached.WaitAsync(Timeout, Ct);
|
||||
|
||||
// In time when the host takes it (2 s of slack), expired by the time the 3 s gate wait gives up.
|
||||
var cmd = new AlarmCommand("alm-1", "AddComment", "alice", "late", null, "cmd-late");
|
||||
var unknown = await host.Ask<AlarmCommandOutcome>(
|
||||
new ScriptedAlarmHostActor.ExecuteAlarmCommand(cmd, DateTime.UtcNow.AddSeconds(2)), Timeout, Ct);
|
||||
unknown.Verdict.ShouldBe(AlarmCommandVerdict.OutcomeUnknown);
|
||||
unknown.Reason!.ShouldContain("did not start the command");
|
||||
|
||||
release.SetResult(null);
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
host.Tell(cmd); // the broadcast copy: not shadowed by a remembered refusal
|
||||
(await Ask(host, "alm-1", "AddComment", "after", "cmd-after")).Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
||||
engine.GetState("alm-1")!.Comments.Select(c => c.Text).ShouldBe(["late", "after"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #953: a load that fails after a newer apply already started its own load is superseded — its failure must not
|
||||
/// publish "refuse everything" while the newer load is in flight (the engine queues a command behind it; the view is
|
||||
/// racy by design and lets through). The newer load's own outcome is what gets published.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_superseded_load_failure_does_not_refuse_commands_while_the_newer_load_runs()
|
||||
{
|
||||
var store = new HoldableStore();
|
||||
var (host, engine, readiness, mux) = Spawn(store);
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1")]));
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
readiness.Refusal().ShouldBeNull();
|
||||
|
||||
// Load 2 holds the gate on alm-2's row read and will fail there; load 3 is applied behind it.
|
||||
var (reached2, release2) = store.Hold("alm-2");
|
||||
var (reached3, release3) = store.Hold("alm-3");
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1"), Plan("alm-2")]));
|
||||
await reached2.WaitAsync(Timeout, Ct);
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1"), Plan("alm-3")]));
|
||||
// Mailbox order: the answer to this ask proves load 3's apply was processed (its generation is the latest).
|
||||
(await Ask(host, "nobody", "Acknowledge")).Verdict.ShouldBe(AlarmCommandVerdict.NotApplied);
|
||||
|
||||
// Load 2 fails; load 3 then takes the gate (clearing the engine's complete-generation flag) and holds it. The
|
||||
// Warning proves the host has processed load 2's failure before the readiness assertion below.
|
||||
await EventFilter.Warning(contains: "LoadAsync failed").ExpectOneAsync(Timeout, async () =>
|
||||
{
|
||||
release2.SetResult(new IOException("database is locked"));
|
||||
await reached3.WaitAsync(Timeout, Ct);
|
||||
}, Ct);
|
||||
engine.HasCompleteGeneration.ShouldBeFalse("load 3 is in flight");
|
||||
readiness.Refusal().ShouldBeNull("a superseded failure publishes nothing — a command queues behind the newer load");
|
||||
|
||||
release3.SetResult(null);
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
readiness.Refusal().ShouldBeNull();
|
||||
(await Ask(host, "alm-3", "AddComment", "ok", "cmd-ok")).Verdict.ShouldBe(AlarmCommandVerdict.Applied);
|
||||
}
|
||||
|
||||
/// <summary>#953 positive control: the LATEST load's failure still publishes the refusal.</summary>
|
||||
[Fact]
|
||||
public async Task The_latest_load_failure_still_refuses_commands()
|
||||
{
|
||||
var store = new HoldableStore();
|
||||
var (host, _, readiness, mux) = Spawn(store);
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1")]));
|
||||
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: Ct);
|
||||
|
||||
var (reached, release) = store.Hold("alm-2");
|
||||
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms([Plan("alm-1"), Plan("alm-2")]));
|
||||
await reached.WaitAsync(Timeout, Ct);
|
||||
release.SetResult(new IOException("database is locked"));
|
||||
AwaitCondition(() => readiness.Refusal() is not null, Timeout, cancellationToken: Ct);
|
||||
(await Ask(host, "alm-1", "Acknowledge")).Verdict.ShouldBe(AlarmCommandVerdict.NotApplied);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user