fix(grpc-data): A1 review round 2 N1 + N2 — withdrawals are never dropped; a discarded mark re-arms F5

N1: the deferral keeps every withdrawal (Known: false) regardless of capacity; a known mark beyond capacity is
dropped (unknown is safe) and its source remembered.
N2: a G3-discarded (or overflowed) deferred mark is reported to its sender as OpcUaPublishActor.ConditionMarksDiscarded
(the scripted host is skipped); DriverHostActor puts those conditions back in the F5 window from now, so a driver
that does not re-signal gets the diagnostic.
This commit is contained in:
Joseph Doherty
2026-11-24 11:34:12 -05:00
parent 4c8539b897
commit 4a6c894268
4 changed files with 127 additions and 6 deletions
@@ -212,6 +212,21 @@ public sealed class NativeAlarmInitialStateSignalTests : NativeAlarmSignalTestBa
AssertNoMark(rig.Publish, TimeSpan.FromSeconds(4.5)); // a stale set would arm the 3 s backstop from this Good edge
}
/// <summary>Review round 2 N2: a discarded mark reported back by the publish actor puts its conditions back in the F5
/// window, so a driver that does not re-signal raises the diagnostic for them.</summary>
[Fact]
public void A_discarded_mark_rearms_F5_for_its_conditions()
{
var rig = StartRig(DriverTypeNames.Galaxy, ["hi", "lo"], o => o.WithSignalTimeout(DriverTypeNames.Galaxy, TimeSpan.FromMilliseconds(400)));
rig.Driver.Signal([A, B]).ShouldBeTrue();
rig.Publish.FishForMessage<OpcUaPublishActor.MarkConditionsKnown>(m => m.Known, TimeSpan.FromSeconds(5), cancellationToken: Ct);
rig.Host.Tell(new OpcUaPublishActor.ConditionMarksDiscarded(DriverId, [A], AddressSpaceRealm.Raw), TestActor);
AwaitCondition(() => rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(5), Ct);
rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(1);
}
/// <summary>Open question answered — re-arm F5 for refs a deploy adds while the driver is connected. Today every such
/// deploy changes the driver's config (its authored RawTags are folded into it), so the driver is respawned: the
/// stopped incarnation's conditions are withdrawn, and the new incarnation's Good edge puts EVERY ref — the added one
@@ -169,6 +169,49 @@ public sealed class OpcUaPublishActorConditionKnownTests : RuntimeActorTestBase
AwaitAssert(() => sink.Completions.ShouldBe([false, true]), PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
}
/// <summary>Review round 2 N1: a deferred withdrawal is never dropped by the deferral's capacity (a known mark may be —
/// unknown is the safe side).</summary>
[Fact]
public void A_withdrawal_beyond_the_deferral_capacity_is_never_dropped()
{
var sink = new OrderSink("al-1");
using var gate = new ManualResetEventSlim(false);
var actor = Sys.ActorOf(OpcUaPublishActor.PropsForTests(
sink, new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance),
new OpcUaPublishActor.TestHooks { BeforePlan = () => gate.Wait() }, deferredWriteCapacity: 1));
actor.Tell(Rebuild());
for (var i = 0; i < 3; i++) actor.Tell(new OpcUaPublishActor.MarkConditionsKnown("drv-1", ["al-1"], AddressSpaceRealm.Uns, Known: false));
AwaitAssert(() => sink.Log.Count(l => l == "unknown:al-1").ShouldBe(3), PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
gate.Set();
ExpectMsg<OpcUaPublishActor.RebuildCompleted>(PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
AwaitAssert(() => sink.Log.Count(l => l == "unknown:al-1").ShouldBe(6), PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
}
/// <summary>Review round 2 N2: a G3 discard of a driver's deferred mark is reported back to the mark's sender, so its
/// F5 tracker counts those conditions as unknown again.</summary>
[Fact]
public void A_discarded_driver_mark_is_reported_to_its_sender()
{
var sink = new OrderSink();
using var gate = new ManualResetEventSlim(false);
var actor = Sys.ActorOf(OpcUaPublishActor.PropsForTests(
sink, new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance),
new OpcUaPublishActor.TestHooks { BeforePlan = () => gate.Wait() }, deferredWriteCapacity: 1));
actor.Tell(Rebuild());
actor.Tell(new OpcUaPublishActor.AttributeValueBatchUpdate([new ValueWrite("Plant/x", 1, OpcUaStatus.Good, DateTime.UtcNow, AddressSpaceRealm.Raw)]));
actor.Tell(new OpcUaPublishActor.AlarmStateUpdate("al-1", Active, DateTime.UtcNow, AddressSpaceRealm.Uns, "drv-1"));
actor.Tell(new OpcUaPublishActor.MarkConditionsKnown("drv-1", ["al-1"], AddressSpaceRealm.Uns));
AwaitAssert(() => sink.Skipped.ShouldContain("alarm:al-1"), PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
gate.Set();
var discarded = FishForMessage<OpcUaPublishActor.ConditionMarksDiscarded>(_ => true, PlanBudget, cancellationToken: TestContext.Current.CancellationToken);
discarded.Source.ShouldBe("drv-1");
discarded.ConditionIds.ShouldBe(["al-1"]);
}
private IActorRef Spawn(OrderSink sink, ManualResetEventSlim gate) =>
Sys.ActorOf(OpcUaPublishActor.PropsForTests(
sink, new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance),