fix(dcl): separator-aware alarm routing, typed reply for browse/search while disconnected, server-timestamp fallback (DCL-5, DCL-6, DCL-7, WP3 task 3.4)
This commit is contained in:
+67
-10
@@ -13,9 +13,11 @@ namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The alarm subscriber first-segment bucket index must make EXACTLY the routing
|
||||
/// decisions the previous linear scan made. The expectation in each case is computed with
|
||||
/// the original rule (plain <c>StartsWith</c> against every subscribed source), so the
|
||||
/// test pins equivalence rather than restating the new implementation.
|
||||
/// decisions a linear scan over every subscribed source makes. The expectation in each case
|
||||
/// is computed with an independent oracle — since the 2026-12-02 review (DCL-5) the rule is
|
||||
/// "the reference is the source itself or lies beneath it at a separator", no longer a raw
|
||||
/// string <c>StartsWith</c> that let <c>Tank1</c> receive <c>Tank10</c>'s alarms — so the test
|
||||
/// pins equivalence rather than restating the implementation.
|
||||
/// </summary>
|
||||
public class DataConnectionActorAlarmIndexTests : TestKit
|
||||
{
|
||||
@@ -37,9 +39,10 @@ public class DataConnectionActorAlarmIndexTests : TestKit
|
||||
|
||||
private static readonly (string SourceRef, string SourceObjectRef)[] Transitions =
|
||||
[
|
||||
("Area1.Tank1.Hi", "Area1.Tank1"), // Area1 (residue) + Area1.Tank
|
||||
("Area1.Tank1.Sub.Hi", "Area1.Tank1.Sub"), // + Area1.Tank1.Sub
|
||||
("Area1X.Pump.Hi", "Area1X.Pump"), // sub-segment prefix: Area1 ONLY
|
||||
("Area1.Tank1.Hi", "Area1.Tank1"), // Area1 (residue) ONLY — "Area1.Tank" is a sibling, not a parent (DCL-5)
|
||||
("Area1.Tank1.Sub.Hi", "Area1.Tank1.Sub"), // Area1 + Area1.Tank1.Sub
|
||||
("Area1.Tank.Hi", "Area1.Tank"), // Area1 + Area1.Tank
|
||||
("Area1X.Pump.Hi", "Area1X.Pump"), // sub-segment prefix of Area1: nobody (DCL-5)
|
||||
("Area2.Tank9.Hi", "Area2.Tank9"), // Area2.Tank only
|
||||
("Zone.A.Hi", "Zone.A"), // nobody
|
||||
];
|
||||
@@ -49,10 +52,12 @@ public class DataConnectionActorAlarmIndexTests : TestKit
|
||||
new AlarmConditionState(true, false, null, AlarmShelveState.Unshelved, false, 500),
|
||||
"Process", "hi", "hi", "", "", null, DateTimeOffset.UtcNow, "92", "90");
|
||||
|
||||
/// <summary>The ORIGINAL linear-scan rule, kept here as the oracle.</summary>
|
||||
/// <summary>The linear-scan oracle: the source itself, or a descendant at a '.' separator.</summary>
|
||||
private static bool LinearScanMatches(string sourceRef, string transitionSourceRef, string transitionSourceObjectRef) =>
|
||||
transitionSourceObjectRef.StartsWith(sourceRef, StringComparison.Ordinal)
|
||||
|| transitionSourceRef.StartsWith(sourceRef, StringComparison.Ordinal);
|
||||
Under(transitionSourceObjectRef, sourceRef) || Under(transitionSourceRef, sourceRef);
|
||||
|
||||
private static bool Under(string reference, string source) =>
|
||||
reference == source || reference.StartsWith(source + ".", StringComparison.Ordinal);
|
||||
|
||||
/// <summary>Verifies that the bucket index routes exactly as the previous linear scan did.</summary>
|
||||
[Fact]
|
||||
@@ -164,7 +169,59 @@ public class DataConnectionActorAlarmIndexTests : TestKit
|
||||
Thread.Sleep(200);
|
||||
|
||||
Assert.NotNull(cb);
|
||||
cb!(Transition("Area1.Tank1.Hi", "Area1.Tank1"));
|
||||
cb!(Transition("Area1.Tank.Hi", "Area1.Tank"));
|
||||
probe.ExpectNoMsg(TimeSpan.FromMilliseconds(300));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DCL-5: sibling sources whose names share a prefix (<c>ns=2;s=Tank1</c> / <c>ns=2;s=Tank10</c>,
|
||||
/// MxGateway <c>Pump1</c> / <c>Pump10</c>) must not receive each other's alarms. Pre-fix every
|
||||
/// <c>Tank10</c> transition was also delivered to — and mirrored by — the <c>Tank1</c> instance.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("ns=2;s=Tank1", "ns=2;s=Tank10")]
|
||||
[InlineData("Pump1", "Pump10")]
|
||||
public void SiblingSourcesSharingAPrefix_DoNotReceiveEachOthersAlarms(string shortSource, string longSource)
|
||||
{
|
||||
AlarmTransitionCallback? cb = null;
|
||||
var adapter = Substitute.For<IDataConnection, IAlarmSubscribableConnection>();
|
||||
adapter.ConnectAsync(Arg.Any<IDictionary<string, string>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
((IAlarmSubscribableConnection)adapter)
|
||||
.SubscribeAlarmsAsync(Arg.Any<string>(), Arg.Any<string?>(),
|
||||
Arg.Do<AlarmTransitionCallback>(c => cb = c), Arg.Any<CancellationToken>())
|
||||
.Returns(ci => Task.FromResult("alarm-" + ci.ArgAt<string>(0)));
|
||||
|
||||
var actor = Sys.ActorOf(Props.Create(() => new DataConnectionActor(
|
||||
"conn", adapter, _options, _health, _factory, "OpcUa")));
|
||||
|
||||
var shortProbe = CreateTestProbe();
|
||||
var longProbe = CreateTestProbe();
|
||||
actor.Tell(new SubscribeAlarmsRequest("c1", "inst-short", "conn", shortSource, null, DateTimeOffset.UtcNow), shortProbe.Ref);
|
||||
shortProbe.ExpectMsg<SubscribeAlarmsResponse>(m => m.Success, TimeSpan.FromSeconds(5));
|
||||
actor.Tell(new SubscribeAlarmsRequest("c2", "inst-long", "conn", longSource, null, DateTimeOffset.UtcNow), longProbe.Ref);
|
||||
longProbe.ExpectMsg<SubscribeAlarmsResponse>(m => m.Success, TimeSpan.FromSeconds(5));
|
||||
|
||||
cb!(Transition(longSource + ".Hi", longSource));
|
||||
longProbe.ExpectMsg<NativeAlarmTransitionUpdate>(TimeSpan.FromSeconds(5));
|
||||
shortProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(300)); // pre-fix: delivered here too
|
||||
|
||||
// The short source still gets its own alarms.
|
||||
cb!(Transition(shortSource + ".Hi", shortSource));
|
||||
shortProbe.ExpectMsg<NativeAlarmTransitionUpdate>(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
/// <summary>The separator-aware containment rule behind alarm routing.</summary>
|
||||
[Theory]
|
||||
[InlineData("Tank1", "Tank1", true)]
|
||||
[InlineData("Tank1.Hi", "Tank1", true)]
|
||||
[InlineData("Area/Tank1", "Area", true)]
|
||||
[InlineData("Tank10", "Tank1", false)]
|
||||
[InlineData("Tank10.Hi", "Tank1", false)]
|
||||
[InlineData("ns=2;s=Tank10", "ns=2;s=Tank1", false)]
|
||||
[InlineData("Area1.Tank", "Area1.", true)]
|
||||
[InlineData("anything", "", true)]
|
||||
[InlineData("Tank", "Tank1", false)]
|
||||
public void IsUnderAlarmSource_IsSeparatorAware(string reference, string source, bool expected) =>
|
||||
Assert.Equal(expected, DataConnectionActor.IsUnderAlarmSource(reference, source));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user