fix(runtime): #869 review round 2 — a carry-through transition no longer settles a pending local ack
NativeAlarmProjector dropped the pending local ack on EVERY driver transition, so an operator ack followed by the alarm returning to normal (a Clear carrying the optimistic ack) inside the confirmation window made a later "not confirmed" report a no-op — the condition stayed inactive+acked while Galaxy showed UNACK_RTN. Only a transition that states the ack (Acknowledge, ActiveAcknowledged, or an un-acking Raise/Retrigger/InactiveUnacknowledged) now settles it; a Clear / same-message Raise / Unspecified update leaves it revertible, and the revert projects inactive+unacked. Tests: projector + host end-to-end (ack, Clear, confirmation fails -> inactive + unacked); tightened the confirmed-ack positive controls; pinned that the confirmation receives the same request instance as AcknowledgeAsync. Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
+15
-6
@@ -9,9 +9,9 @@ using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#869 — <see cref="DriverInstanceActor"/> asks an <see cref="IAlarmAcknowledgeConfirmation"/> driver to
|
||||
/// lmxopcua#869 â <see cref="DriverInstanceActor"/> asks an <see cref="IAlarmAcknowledgeConfirmation"/> driver to
|
||||
/// confirm an ack AFTER <see cref="IAlarmSource.AcknowledgeAsync"/> returned, off its mailbox, and reports
|
||||
/// <see cref="DriverInstanceActor.AlarmAckFailed"/> to the router when the confirmation fails — including one that
|
||||
/// <see cref="DriverInstanceActor.AlarmAckFailed"/> to the router when the confirmation fails â including one that
|
||||
/// fails long after the ack handler returned, and one abandoned because the actor stopped.
|
||||
/// </summary>
|
||||
public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBase
|
||||
@@ -35,6 +35,7 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
var failed = router.ExpectMsg<DriverInstanceActor.AlarmAckFailed>(Timeout, cancellationToken: TestContext.Current.CancellationToken);
|
||||
failed.ConditionNodeId.ShouldBe("n1");
|
||||
failed.Reason.ShouldContain("BadTimeout");
|
||||
driver.ForeignConfirmations.ShouldBe(0, "the confirmation must get the SAME request instance the ack was sent with");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,7 +62,7 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
|
||||
/// <summary>
|
||||
/// A confirmation that succeeds reports nothing. Positive control: a later ack whose confirmation fails is
|
||||
/// reported, and it is the FIRST report the router receives — so none came for the confirmed one.
|
||||
/// reported, and it is the FIRST report the router receives â so none came for the confirmed one.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void A_confirmed_ack_reports_nothing()
|
||||
@@ -70,7 +71,9 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
var actor = SpawnConnected(driver);
|
||||
var router = CreateTestProbe();
|
||||
|
||||
driver.Confirmation = () => Task.Delay(20);
|
||||
// Already complete: the actor's confirmation task finishes (and would report) right after the call that
|
||||
// bumps ConfirmCalls, long before the second ack below makes its actor round trip.
|
||||
driver.Confirmation = () => Task.CompletedTask;
|
||||
actor.Tell(Ack("n-ok"), router.Ref);
|
||||
AwaitCondition(() => driver.ConfirmCalls == 1, Timeout, TestContext.Current.CancellationToken);
|
||||
|
||||
@@ -96,7 +99,12 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
{
|
||||
private int _ackCalls;
|
||||
private int _confirmCalls;
|
||||
private readonly ConcurrentQueue<AlarmAcknowledgeRequest> _acks = new();
|
||||
private readonly ConcurrentQueue<IReadOnlyList<AlarmAcknowledgeRequest>> _ackedLists = new();
|
||||
private int _foreignConfirmations;
|
||||
|
||||
/// <summary>Confirmations asked for a request list that was NOT the instance passed to AcknowledgeAsync —
|
||||
/// the contract a driver matching by instance (Galaxy) relies on.</summary>
|
||||
public int ForeignConfirmations => Volatile.Read(ref _foreignConfirmations);
|
||||
|
||||
public Func<Task>? Confirmation { get; set; }
|
||||
|
||||
@@ -126,7 +134,7 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
public Task AcknowledgeAsync(
|
||||
IReadOnlyList<AlarmAcknowledgeRequest> acknowledgements, CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var a in acknowledgements) _acks.Enqueue(a);
|
||||
_ackedLists.Enqueue(acknowledgements);
|
||||
Interlocked.Increment(ref _ackCalls);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -134,6 +142,7 @@ public sealed class DriverInstanceActorAckConfirmationTests : RuntimeActorTestBa
|
||||
public Task ConfirmAcknowledgedAsync(
|
||||
IReadOnlyList<AlarmAcknowledgeRequest> acknowledgements, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!_ackedLists.Any(l => ReferenceEquals(l, acknowledgements))) Interlocked.Increment(ref _foreignConfirmations);
|
||||
Interlocked.Increment(ref _confirmCalls);
|
||||
return (Confirmation?.Invoke() ?? Task.CompletedTask).WaitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user