diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs index f52ab9ad3..2f86912b7 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionStateHub.cs @@ -195,6 +195,22 @@ public sealed class ConditionStateHub : IConditionStateSink new KeyValuePair("driver", driverInstanceId)); } + /// + /// A raised diagnostic follows its driver's pending set down (a native transition established one of its + /// conditions after the window closed). Only an existing diagnostic is updated, and the counter is not charged + /// again: these conditions were counted when the diagnostic was raised. + /// + /// The driver instance. + /// The conditions still unknown. + /// Whether a raised diagnostic was updated. + public bool UpdateUnsignalled(string driverInstanceId, int conditions) + { + ArgumentException.ThrowIfNullOrEmpty(driverInstanceId); + while (_unsignalled.TryGetValue(driverInstanceId, out var current)) + if (_unsignalled.TryUpdate(driverInstanceId, current with { Conditions = conditions }, current)) return true; + return false; + } + /// A later signal (or the driver's removal) clears the diagnostic. /// The driver instance. /// Whether a diagnostic was cleared. diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.ConditionSignals.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.ConditionSignals.cs index e28695dba..c24eb455e 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.ConditionSignals.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverHostActor.ConditionSignals.cs @@ -237,8 +237,13 @@ public sealed partial class DriverHostActor private void NoteConditionsEstablished(string driverInstanceId, ConditionSignalTracker t, IEnumerable rawPaths) { if (t.Pending.Count == 0) return; + var before = t.Pending.Count; t.Pending.ExceptWith(rawPaths); if (t.Pending.Count == 0) ClearPendingWindow(driverInstanceId, t); + // A2 review (A1 phase-run failure): a diagnostic raised before this transition must not keep claiming the + // condition — the node manager holds it established now. + else if (t.DiagnosticRaised && t.Pending.Count != before) + _conditionSignals.Hub?.UpdateUnsignalled(driverInstanceId, t.Pending.Count); } /// A forwarded native transition established (see ). diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmInitialStateSignalTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmInitialStateSignalTests.cs index c7cff0fb2..bfd05f067 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmInitialStateSignalTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmInitialStateSignalTests.cs @@ -259,8 +259,29 @@ public sealed class NativeAlarmInitialStateSignalTests : NativeAlarmSignalTestBa rig.Driver.Raise(A).ShouldBeTrue(); rig.Publish.FishForMessage(u => u.AlarmNodeId == A, TimeSpan.FromSeconds(5), cancellationToken: Ct); + // Either order is legal: the transition can land before the F5 window closes (the diagnostic is raised with 1) or + // after it (raised with 2, then lowered to 1). The diagnostic must end at the node manager's count either way. + AwaitCondition(() => rig.Hub.Unsignalled.TryGetValue(DriverId, out var d) && d.Conditions == 1, TimeSpan.FromSeconds(5), Ct); + } + + /// + /// A2 review (the A1 phase-run failure): the F5 window closes BEFORE the transition arrives — what a loaded run + /// does to the 600 ms window above. The raised diagnostic must follow the pending set down (it used to keep the + /// count from when it was raised, so it claimed a condition the node manager already held established). + /// + [Fact] + public void A_native_transition_after_the_F5_window_closed_lowers_the_raised_diagnostic() + { + var rig = StartRig(DriverTypeNames.Galaxy, ["hi", "lo"], o => o.WithSignalTimeout(DriverTypeNames.Galaxy, TimeSpan.FromMilliseconds(200))); AwaitCondition(() => rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(5), Ct); - rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(1); // only B is still unknown + rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(2); + + rig.Driver.Raise(A).ShouldBeTrue(); + rig.Publish.FishForMessage(u => u.AlarmNodeId == A, TimeSpan.FromSeconds(5), cancellationToken: Ct); + AwaitCondition(() => rig.Hub.Unsignalled.TryGetValue(DriverId, out var d) && d.Conditions == 1, TimeSpan.FromSeconds(5), Ct); + + rig.Driver.Raise(B).ShouldBeTrue(); // the last pending condition established ⇒ the diagnostic clears + AwaitCondition(() => !rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(5), Ct); } /// Review nit — a signal from anything but the current child (a stopped incarnation, a stray sender) is