diff --git a/scripts/validation/grpc-data/unit-phases.json b/scripts/validation/grpc-data/unit-phases.json
index 545b4ddf0..a7deca1d9 100644
--- a/scripts/validation/grpc-data/unit-phases.json
+++ b/scripts/validation/grpc-data/unit-phases.json
@@ -974,7 +974,8 @@
"OpcUaPublishActorConditionKnownTests",
"NativeAlarmInitialStateSignalTests",
"ScriptedAlarmHostInputsEstablishedTests",
- "GrpcDataConditionPlacementTests"
+ "GrpcDataConditionPlacementTests",
+ "RealDriverInitialStateSignalTests"
],
"existing_classes": [
"OpcUaPublishActorDeferredWriteTests",
@@ -1020,6 +1021,54 @@
"existing_classes": [
"GrpcDataV1RealOriginCompatibilityTests"
]
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests/ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "GalaxyInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "OpcUaClientInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests/ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "FocasInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests/ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "AbCipInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.Tests/ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "HeidenhainInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
+ },
+ {
+ "project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests.csproj",
+ "filter": "(Feature=GrpcData&Phase=A1)",
+ "new_classes": [
+ "MTConnectInitialAlarmStateSignalTests"
+ ],
+ "existing_classes": []
}
]
}
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmSignalTestBase.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmSignalTestBase.cs
index f3c09d527..92cacc726 100644
--- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmSignalTestBase.cs
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/NativeAlarmSignalTestBase.cs
@@ -55,10 +55,30 @@ public abstract class NativeAlarmSignalTestBase : RuntimeActorTestBase
/// The rig.
protected Rig StartRig(string driverType, IReadOnlyList alarmTags,
Func? configure = null, FakeSignallingAlarmDriver? driver = null)
+ {
+ driver ??= new FakeSignallingAlarmDriver(DriverId, driverType);
+ var fake = driver;
+ var (host, publish, hub) = StartRig(driver, driverType, alarmTags, configure, () => fake.Subscribed);
+ return new Rig(host, publish, driver, hub);
+ }
+
+ ///
+ /// The same rig over ANY (a REAL driver over a fake device): deploys
+ /// on it and waits for the apply, then for (e.g. the real
+ /// driver's alarm subscription) when given.
+ ///
+ /// The driver the host spawns (its must be ).
+ /// The driver type.
+ /// The alarm tag names (RawPaths per ).
+ /// Adjusts the signal options (timeouts).
+ /// Optional readiness predicate awaited after the apply.
+ /// The host, the publish probe and the hub.
+ protected (IActorRef Host, TestProbe Publish, ConditionStateHub Hub) StartRig(IDriver driver, string driverType,
+ IReadOnlyList alarmTags, Func? configure = null,
+ Func? ready = null)
{
var db = NewInMemoryDbFactory();
var deploymentId = Seed(db, driverType, alarmTags);
- driver ??= new FakeSignallingAlarmDriver(DriverId, driverType);
var hub = new ConditionStateHub();
var options = new ConditionSignalOptions { Hub = hub };
options = configure?.Invoke(options) ?? options;
@@ -77,8 +97,8 @@ public abstract class NativeAlarmSignalTestBase : RuntimeActorTestBase
host.Tell(new DispatchDeployment(deploymentId, Rev, CorrelationId.NewId()));
coordinator.FishForMessage(_ => true, TimeSpan.FromSeconds(10), cancellationToken: TestContext.Current.CancellationToken).Outcome.ShouldBe(ApplyAckOutcome.Applied);
- AwaitCondition(() => driver.Subscribed, TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
- return new Rig(host, publish, driver, hub);
+ if (ready is not null) AwaitCondition(ready, TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
+ return (host, publish, hub);
}
/// Negative control: for , the probe receives no
diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/RealDriverInitialStateSignalTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/RealDriverInitialStateSignalTests.cs
new file mode 100644
index 000000000..9c6adaf17
--- /dev/null
+++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/RealDriverInitialStateSignalTests.cs
@@ -0,0 +1,148 @@
+using System.Text.Json;
+using Shouldly;
+using Xunit;
+using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
+using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
+using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
+using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
+using ZB.MOM.WW.OtOpcUa.Runtime.OpcUa;
+
+namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
+
+///
+/// grpc-data A1 T2 (ii)/(viii) END TO END with a REAL driver: the real (over a fake CNC)
+/// spawned by the real + DriverInstanceActor through the native-alarm signal
+/// rig. The initial replay (a standing alarm read after quality Good) projects Active BEFORE the condition is marked
+/// known, and only by the driver's ; a second, unreachable CNC's condition is
+/// never marked and its F5 diagnostic does not touch the reachable one.
+///
+[Trait("Feature", "GrpcData")]
+[Trait("Phase", "A1")]
+public sealed class RealDriverInitialStateSignalTests : NativeAlarmSignalTestBase
+{
+ private const string HostA = "focas://10.0.0.5:8193";
+ private const string HostB = "focas://10.0.0.6:8193";
+ private static readonly string Servo = RawPathOf("servo");
+ private static readonly string ServoB = RawPathOf("servo_b");
+
+ private static CancellationToken Ct => TestContext.Current.CancellationToken;
+
+ /// (ii) FOCAS: the standing alarm's Active projection precedes the mark; the mark is the only way known.
+ [Fact]
+ public async Task Focas_standing_alarm_projects_before_its_condition_is_marked_known()
+ {
+ var driver = Focas([("servo", HostA)], new CncFactory(standingOn: HostA, unreachable: null));
+
+ var rig = StartRig(driver, DriverTypeNames.FOCAS, ["servo"]);
+
+ var traffic = CollectAlarmTraffic(rig.Publish, m => m is OpcUaPublishActor.MarkConditionsKnown);
+ traffic[0].ShouldBeOfType().AlarmNodeId.ShouldBe(Servo);
+ ((OpcUaPublishActor.AlarmStateUpdate)traffic[0]).State.Active.ShouldBeTrue();
+ var mark = traffic[^1].ShouldBeOfType();
+ mark.Source.ShouldBe(DriverId);
+ mark.Realm.ShouldBe(AddressSpaceRealm.Raw);
+ mark.ConditionIds.ShouldBe([Servo]);
+ await driver.ShutdownAsync(Ct);
+ }
+
+ ///
+ /// (viii) G1: CNC B never answers its alarm read. A's condition is marked known; B's never is; after the F5
+ /// timeout the diagnostic counts B alone, and A stays known (no unknown record for it).
+ ///
+ [Fact]
+ public async Task Focas_unreachable_cnc_stays_unknown_without_affecting_the_reachable_one()
+ {
+ var driver = Focas([("servo", HostA), ("servo_b", HostB)], new CncFactory(standingOn: null, unreachable: HostB));
+
+ var rig = StartRig(driver, DriverTypeNames.FOCAS, ["servo", "servo_b"],
+ o => o.WithSignalTimeout(DriverTypeNames.FOCAS, TimeSpan.FromSeconds(2)),
+ ready: null);
+
+ var first = rig.Publish.FishForMessage(_ => true, TimeSpan.FromSeconds(10), cancellationToken: Ct);
+ first.ConditionIds.ShouldBe([Servo]);
+
+ AwaitCondition(() => rig.Hub.Unsignalled.ContainsKey(DriverId), TimeSpan.FromSeconds(10), Ct);
+ rig.Hub.Unsignalled[DriverId].Conditions.ShouldBe(1, "only B is still unsignalled");
+
+ // A keeps being re-established every poll; B never appears in any mark, and nothing marks A unknown.
+ var deadline = DateTime.UtcNow + TimeSpan.FromMilliseconds(500);
+ while (DateTime.UtcNow < deadline)
+ {
+ if (rig.Publish.ReceiveOne(deadline - DateTime.UtcNow, Ct) is OpcUaPublishActor.MarkConditionsKnown m)
+ {
+ m.ConditionIds.ShouldNotContain(ServoB);
+ m.Known.ShouldBeTrue();
+ }
+ }
+
+ await driver.ShutdownAsync(Ct);
+ }
+
+ private static FocasDriver Focas(IReadOnlyList<(string Tag, string Host)> tags, CncFactory factory) =>
+ new(new FocasDriverOptions
+ {
+ Devices = [.. tags.Select(t => t.Host).Distinct().Select(h => new FocasDeviceOptions(h, DeviceName: h))],
+ RawTags =
+ [
+ .. tags.Select(t => new RawTagEntry(RawPathOf(t.Tag), JsonSerializer.Serialize(new Dictionary
+ {
+ ["address"] = "ALARM:Servo",
+ ["dataType"] = "Int32",
+ ["alarm"] = new Dictionary { ["alarmType"] = "AlarmCondition" },
+ }), WriteIdempotent: false, DeviceName: t.Host)),
+ ],
+ Probe = new FocasProbeOptions { Enabled = false },
+ AlarmProjection = new FocasAlarmProjectionOptions { PollInterval = TimeSpan.FromMilliseconds(50) },
+ }, DriverId, factory);
+
+ /// Hands out one fake CNC per connect; the CNC learns its host on ConnectAsync.
+ private sealed class CncFactory(string? standingOn, string? unreachable) : IFocasClientFactory
+ {
+ public IFocasClient Create() => new Cnc(standingOn, unreachable);
+
+ public void EnsureUsable() { }
+ }
+
+ private sealed class Cnc(string? standingOn, string? unreachable) : IFocasClient
+ {
+ private string? _host;
+
+ public bool IsConnected { get; private set; }
+
+ public Task ConnectAsync(FocasHostAddress address, TimeSpan timeout, CancellationToken cancellationToken)
+ {
+ _host = $"focas://{address.Host}:{address.Port}";
+ IsConnected = true;
+ return Task.CompletedTask;
+ }
+
+ public Task> ReadAlarmsAsync(CancellationToken cancellationToken)
+ {
+ if (_host == unreachable) throw new IOException("CNC unreachable (fake)");
+ IReadOnlyList alarms = _host == standingOn
+ ? [new FocasActiveAlarm(401, FocasAlarmType.Servo, 1, "SERVO V-READY OFF")]
+ : [];
+ return Task.FromResult(alarms);
+ }
+
+ public Task ProbeAsync(CancellationToken cancellationToken) => Task.FromResult(true);
+
+ public void Dispose() => IsConnected = false;
+
+ public Task<(object? value, uint status)> ReadAsync(FocasAddress address, FocasDataType type, CancellationToken cancellationToken) => throw Unused();
+ public Task WriteAsync(FocasAddress address, FocasDataType type, object? value, CancellationToken cancellationToken) => throw Unused();
+ public Task<(IReadOnlyList? slots, uint status)> ReadPmcSlotsAsync(string letter, FocasDataType slotType, int start, int end, CancellationToken cancellationToken) => throw Unused();
+ public Task GetSysInfoAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task> GetAxisNamesAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task> GetSpindleNamesAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task ReadDynamicAsync(int axisIndex, CancellationToken cancellationToken) => throw Unused();
+ public Task GetProgramInfoAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task GetStatusAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task GetTimerAsync(FocasTimerKind kind, CancellationToken cancellationToken) => throw Unused();
+ public Task> GetServoLoadsAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task> GetSpindleLoadsAsync(CancellationToken cancellationToken) => throw Unused();
+ public Task> GetSpindleMotorSpeedsAsync(CancellationToken cancellationToken) => throw Unused();
+
+ private static NotSupportedException Unused() => new("not reached by the alarm signal test");
+ }
+}