From 647b7f631e069b3d137bf7713dea677e7af971fc Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 1 Dec 2026 20:18:13 -0500 Subject: [PATCH 1/2] feat(adminui): #954 OpcUaClient driver form field for AlarmRefreshRequiredMinInterval (+ round-trip and factory-parse tests) --- .../Drivers/Forms/OpcUaClientDriverForm.razor | 10 +++++++ ...UaClientAlarmRefreshIntervalConfigTests.cs | 29 ++++++++++++++++++ ...aClientDriverPageFormSerializationTests.cs | 30 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/OpcUaClientAlarmRefreshIntervalConfigTests.cs diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Drivers/Forms/OpcUaClientDriverForm.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Drivers/Forms/OpcUaClientDriverForm.razor index ee3591117..ee69b9726 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Drivers/Forms/OpcUaClientDriverForm.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Drivers/Forms/OpcUaClientDriverForm.razor @@ -229,6 +229,12 @@
@if (_fieldEditContext is not null) { }
+
+ + +
@if (_fieldEditContext is not null) { }
+
Minimum spacing between RefreshRequired-triggered alarm ConditionRefresh sweeps. Default 10; 0 = no limit (#946).
+
@@ -376,6 +382,8 @@ public int TimeoutSeconds { get; set; } = 10; public int SessionTimeoutSeconds { get; set; } = 120; public int KeepAliveIntervalSeconds { get; set; } = 5; + // #954: double (not int) so a hand-authored sub-second value is not truncated to 0 (= limit off) on save. + public double AlarmRefreshRequiredMinIntervalSeconds { get; set; } = 10; public int MaxDiscoveredNodes { get; set; } = 10_000; public int MaxBrowseDepth { get; set; } = 10; @@ -418,6 +426,7 @@ TimeoutSeconds = (int)r.Timeout.TotalSeconds, SessionTimeoutSeconds = (int)r.SessionTimeout.TotalSeconds, KeepAliveIntervalSeconds = (int)r.KeepAliveInterval.TotalSeconds, + AlarmRefreshRequiredMinIntervalSeconds = r.AlarmRefreshRequiredMinInterval.TotalSeconds, MaxDiscoveredNodes = r.MaxDiscoveredNodes, MaxBrowseDepth = r.MaxBrowseDepth, SecurityMode = r.SecurityMode, @@ -458,6 +467,7 @@ Timeout = TimeSpan.FromSeconds(TimeoutSeconds), SessionTimeout = TimeSpan.FromSeconds(SessionTimeoutSeconds), KeepAliveInterval = TimeSpan.FromSeconds(KeepAliveIntervalSeconds), + AlarmRefreshRequiredMinInterval = TimeSpan.FromSeconds(Math.Max(AlarmRefreshRequiredMinIntervalSeconds, 0)), MaxDiscoveredNodes = MaxDiscoveredNodes, MaxBrowseDepth = MaxBrowseDepth, SecurityMode = SecurityMode, diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/OpcUaClientAlarmRefreshIntervalConfigTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/OpcUaClientAlarmRefreshIntervalConfigTests.cs new file mode 100644 index 000000000..d021af614 --- /dev/null +++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/OpcUaClientAlarmRefreshIntervalConfigTests.cs @@ -0,0 +1,29 @@ +using System.Text.Json; +using Shouldly; +using Xunit; +using ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient; + +namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests; + +/// #954: the factory parses the AlarmRefreshRequiredMinInterval shape the AdminUI form writes. +public sealed class OpcUaClientAlarmRefreshIntervalConfigTests +{ + [Theory] + [InlineData("""{"endpointUrl":"opc.tcp://x:1","alarmRefreshRequiredMinInterval":"00:00:30"}""", 30.0)] + [InlineData("""{"endpointUrl":"opc.tcp://x:1","alarmRefreshRequiredMinInterval":"00:00:00"}""", 0.0)] + [InlineData("""{"endpointUrl":"opc.tcp://x:1","alarmRefreshRequiredMinInterval":"00:00:00.5000000"}""", 0.5)] + [InlineData("""{"endpointUrl":"opc.tcp://x:1"}""", 10.0)] + public void ParseOptions_ReadsFormShape(string json, double expectedSeconds) => + OpcUaClientDriverFactoryExtensions.ParseOptions("d", json).AlarmRefreshRequiredMinInterval + .ShouldBe(TimeSpan.FromSeconds(expectedSeconds)); + + [Fact] + public void ParseOptions_ReadsSerializedOptions() + { + var json = JsonSerializer.Serialize( + new OpcUaClientDriverOptions { AlarmRefreshRequiredMinInterval = TimeSpan.FromSeconds(7) }, + new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + OpcUaClientDriverFactoryExtensions.ParseOptions("d", json).AlarmRefreshRequiredMinInterval + .ShouldBe(TimeSpan.FromSeconds(7)); + } +} diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/OpcUaClientDriverPageFormSerializationTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/OpcUaClientDriverPageFormSerializationTests.cs index 659c3baa3..bebd3a314 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/OpcUaClientDriverPageFormSerializationTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/OpcUaClientDriverPageFormSerializationTests.cs @@ -142,6 +142,36 @@ public sealed class OpcUaClientDriverPageFormSerializationTests result.ProbeTimeoutSeconds.ShouldBe(25); } + /// #954: AlarmRefreshRequiredMinInterval must survive the form (default 10 s; 0 = off; sub-second kept). + [Theory] + [InlineData(10.0)] + [InlineData(0.0)] + [InlineData(45.0)] + [InlineData(0.5)] + public void FormModel_RoundTrip_PreservesAlarmRefreshRequiredMinInterval(double seconds) + { + var original = new OpcUaClientDriverOptions { AlarmRefreshRequiredMinInterval = TimeSpan.FromSeconds(seconds) }; + + var form = OpcUaClientDriverForm.OpcUaClientFormModel.FromRecord(original); + form.AlarmRefreshRequiredMinIntervalSeconds.ShouldBe(seconds); + var back = form.ToRecord([]); + + back.AlarmRefreshRequiredMinInterval.ShouldBe(TimeSpan.FromSeconds(seconds)); + // Through the wire shape the form emits (camelCase options JSON, TimeSpan as "hh:mm:ss"). + var json = JsonSerializer.Serialize(back, _opts); + JsonSerializer.Deserialize(json, _opts)! + .AlarmRefreshRequiredMinInterval.ShouldBe(TimeSpan.FromSeconds(seconds)); + } + + [Fact] + public void FormModel_DefaultAlarmRefreshRequiredMinInterval_MatchesDriverDefault() + { + new OpcUaClientDriverForm.OpcUaClientFormModel().ToRecord([]).AlarmRefreshRequiredMinInterval + .ShouldBe(new OpcUaClientDriverOptions().AlarmRefreshRequiredMinInterval); + new OpcUaClientDriverForm.OpcUaClientFormModel { AlarmRefreshRequiredMinIntervalSeconds = -5 }.ToRecord([]) + .AlarmRefreshRequiredMinInterval.ShouldBe(TimeSpan.Zero); + } + /// /// #273/#275/#277/#278: the typed form rewrites the whole record on save, so a key it does not model /// is silently dropped (#576). Every new option must survive FromRecord -> ToRecord. From 601ade22438163fa05d7e19e23145caecbd2f5f5 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 1 Dec 2026 20:18:19 -0500 Subject: [PATCH 2/2] docs(opcuaclient): #954 note AdminUI field --- docs/drivers/OpcUaClient.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/drivers/OpcUaClient.md b/docs/drivers/OpcUaClient.md index 12fb0d8a7..0db6e2377 100644 --- a/docs/drivers/OpcUaClient.md +++ b/docs/drivers/OpcUaClient.md @@ -476,7 +476,7 @@ initialise (the AdminUI form drops them on the next save). Pinned by > - **RefreshRequired:** its sweeps are coalesced while one is queued **and rate-limited (#946)**: at least > `alarmRefreshRequiredMinInterval` (default 10 s, start to start; `00:00:00` disables) separates two sweeps on one > session. A request inside the window is **deferred** to the window's end, never dropped, and everything arriving -> meanwhile coalesces into that one sweep; a new session starts a fresh window. Reconnect / re-subscribe / loss-retry +> meanwhile coalesces into that one sweep; a new session starts a fresh window. AdminUI: "Alarm RefreshRequired min interval (s)" on the driver form (#954). Reconnect / re-subscribe / loss-retry > refreshes (own 3-attempt budget) are not subject to it. The alarm event item asks for a > queue of 10,000 (previously 1,000); the server may revise it down. Counters on `otopcua.driver.opcuaclient.events`: > `alarm_event_queue_overflow` and `alarm_refresh_lossy`.