fix(grpc-data): A1 review round 2 F3 — an MTConnect delta signals the conditions it touched

A condition Unavailable at baseline never became known: its later Normal is a quality-only emission and only full
emissions signalled. A delta emission now signals its touched conditions whose level is not Unavailable, after the
events and under the same lock (tracker baseline required). Sample_delta_does_not_signal… (which pinned the old
behaviour) is now Sample_delta_signals_its_touched_conditions_and_a_rebaseline_signals_all.
This commit is contained in:
Joseph Doherty
2026-11-24 11:28:14 -05:00
parent 4d21ccafa1
commit ea19c3ed4f
2 changed files with 39 additions and 11 deletions
@@ -78,7 +78,8 @@ public sealed partial class MTConnectDriver : IAlarmSource, IAlarmInitialStateSi
/// grpc-data A1 (§5.1 MTConnect row): raised after a FULL emission (the resync in
/// <see cref="SubscribeAlarmsAsync"/>, the restarted pump's first act, comms-loss recovery) over a tracker
/// built from a <c>/current</c> baseline, covering every subscribed condition whose level is known and not
/// <c>Unavailable</c> (an Unavailable item is the device not reporting — it stays unknown).
/// <c>Unavailable</c> (an Unavailable item is the device not reporting — it stays unknown); and after a DELTA
/// emission, covering the touched conditions whose level is not <c>Unavailable</c> (review round 2 F3).
/// </remarks>
public event EventHandler<AlarmInitialStateEventArgs>? InitialAlarmStateDelivered;
@@ -220,15 +221,19 @@ public sealed partial class MTConnectDriver : IAlarmSource, IAlarmInitialStateSi
}
// grpc-data A1: a full emission (or a re-baseline) over a /current baseline establishes every subscribed
// condition it can judge — known and not Unavailable. After every event of this emission, under the same
// lock and handler gate (F2, G5).
if ((touchedDataItemIds is null || baselineRead) && tracker.HasBaseline)
// condition it can judge — known and not Unavailable. A DELTA emission (A1 review round 2 F3) establishes
// the conditions it touched that now report a level other than Unavailable — so a condition Unavailable at
// baseline becomes known when it later reports (e.g. Normal, whose emission is only quality). After every
// event of this emission, under the same lock and handler gate (F2, G5).
if (tracker.HasBaseline)
{
var full = touchedDataItemIds is null || baselineRead;
var established = new List<string>();
foreach (var conditionId in subscription.References)
{
if (tracker.Get(binding.ToDataItemId(conditionId)) is { } state
&& state.Level != MTConnectConditionLevel.Unavailable)
var dataItemId = binding.ToDataItemId(conditionId);
if (!full && !touchedDataItemIds!.Contains(dataItemId)) continue;
if (tracker.Get(dataItemId) is { } state && state.Level != MTConnectConditionLevel.Unavailable)
established.Add(conditionId);
}
@@ -56,9 +56,10 @@ public sealed class MTConnectInitialAlarmStateSignalTests
await driver.ShutdownAsync(Ct);
}
/// <summary>A /sample delta is not a full emission: no signal. An Agent restart's re-baseline (the restarted pump's first act) is.</summary>
/// <summary>A /sample delta signals the conditions it touched (review round 2 F3), after its event; an Agent
/// restart's re-baseline (the restarted pump's first act) signals them all.</summary>
[Fact]
public async Task Sample_delta_does_not_signal_and_a_rebaseline_does()
public async Task Sample_delta_signals_its_touched_conditions_and_a_rebaseline_signals_all()
{
var agent = CannedAgentClient.FromFixtures();
agent.Current = new MTConnectStreamsResult(InstanceId, 108, 1, [Cond(CondItem, "Normal")]);
@@ -68,15 +69,37 @@ public sealed class MTConnectInitialAlarmStateSignalTests
await agent.PumpAsync(new MTConnectStreamsResult(InstanceId, 109, 108, [Cond(CondItem, "Fault", "E17")]))
.WaitAsync(Watchdog, Ct);
Snapshot(trace).ShouldBe(["signal:" + CondPath, "event:" + CondPath + ":Raise"]);
Snapshot(trace).ShouldBe(["signal:" + CondPath, "event:" + CondPath + ":Raise", "signal:" + CondPath]);
agent.CurrentAnswers.Enqueue(new MTConnectStreamsResult(RestartedInstanceId, 5, 1, [Cond(CondItem, "Normal")]));
await agent.PumpAsync(new MTConnectStreamsResult(RestartedInstanceId, 4, 1, [])).WaitAsync(Watchdog, Ct);
await agent.WaitForSampleCallsAsync(2).WaitAsync(Watchdog, Ct);
await WaitFor(() => Snapshot(trace).Length >= 4);
await WaitFor(() => Snapshot(trace).Length >= 5);
Snapshot(trace).ShouldBe(
["signal:" + CondPath, "event:" + CondPath + ":Raise", "event:" + CondPath + ":Clear", "signal:" + CondPath]);
["signal:" + CondPath, "event:" + CondPath + ":Raise", "signal:" + CondPath, "event:" + CondPath + ":Clear", "signal:" + CondPath]);
await driver.ShutdownAsync(Ct);
}
/// <summary>Review round 2 F3: a condition Unavailable at baseline becomes known when a later delta reports it (here
/// Normal, whose emission is quality-only) — the signal follows that emission. A delta that leaves it Unavailable
/// signals nothing.</summary>
[Fact]
public async Task A_condition_Unavailable_at_baseline_is_signalled_when_a_delta_reports_it()
{
var agent = CannedAgentClient.FromFixtures();
agent.Current = new MTConnectStreamsResult(InstanceId, 108, 1, [Cond(CondItem, "UNAVAILABLE"), Cond(OtherItem, "Normal")]);
var (driver, trace) = await StartAsync(agent);
await driver.SubscribeAlarmsAsync([CondPath, OtherPath], Ct);
var before = Snapshot(trace).Length;
await agent.PumpAsync(new MTConnectStreamsResult(InstanceId, 109, 108, [Cond(OtherItem, "UNAVAILABLE")])).WaitAsync(Watchdog, Ct);
await agent.PumpAsync(new MTConnectStreamsResult(InstanceId, 110, 109, [Cond(CondItem, "Normal")])).WaitAsync(Watchdog, Ct);
await WaitFor(() => Snapshot(trace).Skip(before).Any(t => t == "signal:" + CondPath));
var after = Snapshot(trace).Skip(before).ToList();
after.Where(t => t.StartsWith("signal", StringComparison.Ordinal)).ShouldBe(["signal:" + CondPath]); // not OtherPath
after.Last().ShouldBe("signal:" + CondPath); // after the emission's events
await driver.ShutdownAsync(Ct);
}