feat(opcua): per-item delivery for folder event items; folder ConditionRefresh gets the #854 cut (#855)
Condition events reaching one of our notifiers no longer go through the SDK MonitoredNode2 channel: the walk serves the attached items itself, per item and per event (audit guard, uncached INodeManager3 verdict, item gate/cut, QueueEvent), as the Server-object path does. No notifier of ours defers any more; the #838 deferral queue and the #854 cut stay as the safety net and folder items share the cut (RefreshDirectItems, flag on and off). An event whose walk suspends is marked deferred before it suspends. Tests produce deferral with a notifier-stall probe instead of holding a folder item's SDK lock (which would now block the reporter). New FolderConditionRefreshWireTests; design note in docs/plans. Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
+18
-13
@@ -27,13 +27,16 @@ namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests;
|
||||
/// <item>no ACL-denied event reaches an item during the overflow, including deferred events whose grant was
|
||||
/// revoked while they waited.</item>
|
||||
/// </list>
|
||||
/// Since Gitea #855 the folder items are served per item by the reporter (as the Server-object items always were),
|
||||
/// so the flood no longer defers at all — the first test pins that — and the revocation test stalls the folder's
|
||||
/// delivery (<see cref="NotifierStall"/>) to get a deferred backlog.
|
||||
/// </summary>
|
||||
public sealed class EventQueueOverflowAclWireTests
|
||||
{
|
||||
private const string EqA = ServerEventRig.EqA;
|
||||
private const string EqB = ServerEventRig.EqB;
|
||||
|
||||
// Native events per flood: past the SDK's 4096-slot per-notifier channel, so the native condition defers.
|
||||
// Native events per flood: past the SDK's 4096-slot per-notifier channel (which deferred them before #855).
|
||||
private const int PerCondition = 6000;
|
||||
|
||||
/// <param name="singleHold">
|
||||
@@ -150,13 +153,12 @@ public sealed class EventQueueOverflowAclWireTests
|
||||
readLatencies.Max().ShouldBeLessThan(TimeSpan.FromSeconds(5), "a Read must not queue behind the whole flood");
|
||||
(await TimedReadAsync(anonymous, eqA, ct)).ShouldBeLessThan(TimeSpan.FromSeconds(2), "the node manager is free afterwards");
|
||||
|
||||
// Memory: the node manager's own overflow store stayed within its per-condition budget (queued + in flight)…
|
||||
Volatile.Read(ref peakDeferred).ShouldBeLessThanOrEqualTo(
|
||||
2 * (OtOpcUaNodeManager.MaxDeferredEventsPerCondition + 1), "deferral is bounded per condition");
|
||||
if (singleHold) rig.Nm.DiscardedEventReports.ShouldBeGreaterThan(0, "the native tail overflowed and coalesced");
|
||||
// Memory: the node manager held nothing of its own for the overflow (#855: no notifier of ours defers, so the
|
||||
// item queues are the only store, bounded below)…
|
||||
Volatile.Read(ref peakDeferred).ShouldBe(0, "folder items are served per item by the reporter: nothing defers");
|
||||
rig.Nm.DiscardedEventReports.ShouldBe(0);
|
||||
|
||||
// …let the SDK channel finish draining into the (still unpublished) item queues, then publish.
|
||||
await Task.Delay(TimeSpan.FromSeconds(2), ct);
|
||||
// …then publish the (still unpublished) item queues.
|
||||
await keySub.SetPublishingModeAsync(true, ct);
|
||||
var lastNative = $"n{PerCondition - 1}";
|
||||
await RecordedEvents.WaitUntilAsync(() => keyEvents.Has(onB, lastNative) && keyEvents.Has(keyServer, lastNative));
|
||||
@@ -165,10 +167,9 @@ public sealed class EventQueueOverflowAclWireTests
|
||||
foreach (var item in new[] { onB, keyServer })
|
||||
{
|
||||
var received = keyEvents.Of(item);
|
||||
// ACL: not one event of the denied (EqA-owned) scripted alarm, overflow or not. (Under a single hold the
|
||||
// deferred native tail drains last and evicts every synchronously-queued event from the 1000-slot queue, so
|
||||
// there this check cannot see a leak; the "after-s" leg below is the falsifier for that mode — verified by
|
||||
// running with enforcement off: chunked fails here, single-hold fails at "after-s".)
|
||||
// ACL: not one event of the denied (EqA-owned) scripted alarm, overflow or not. (The 1000-slot queue keeps
|
||||
// only the last events of the flood, which interleave n/s, so a leak shows here in both modes; the
|
||||
// "after-s" leg below is a second falsifier.)
|
||||
received.Where(f => RecordedEvents.Message(f)?.StartsWith('s') == true)
|
||||
.ShouldBeEmpty($"{item.DisplayName}: an ACL-denied event leaked during the overflow");
|
||||
|
||||
@@ -211,7 +212,7 @@ public sealed class EventQueueOverflowAclWireTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A grant revoked while a deferred backlog waits behind a full notifier channel: the deferred events are decided
|
||||
/// A grant revoked while a deferred backlog waits behind a stalled notifier: the deferred events are decided
|
||||
/// at delivery against the CURRENT generation, so none of them — nor any event reported after the revocation —
|
||||
/// reaches the revoked session's folder or Server-object item, while a still-granted session sharing the same
|
||||
/// folder channel receives the whole tail (positive control).
|
||||
@@ -249,6 +250,9 @@ public sealed class EventQueueOverflowAclWireTests
|
||||
await anonSub.ApplyChangesAsync(ct);
|
||||
anonA.Status.Error.ShouldBeNull();
|
||||
|
||||
// The EqA folder's delivery stalls (#855: nothing of ours defers on its own any more), so the native condition's
|
||||
// walk suspends there and the rest of the flood is deferred behind it.
|
||||
using var stall = NotifierStall.Hold(rig.Nm, EqA);
|
||||
var flood = Task.Factory.StartNew(() =>
|
||||
{
|
||||
lock (rig.Nm.Lock)
|
||||
@@ -276,11 +280,12 @@ public sealed class EventQueueOverflowAclWireTests
|
||||
throw new ShouldAssertException("revoking a grant under Lock while events were deferred stalled (deadlock)");
|
||||
}
|
||||
|
||||
stall.Release();
|
||||
await RecordedEvents.WaitUntilAsync(() => rig.Nm.DeferredEventReports == 0);
|
||||
await Task.Delay(TimeSpan.FromSeconds(2), ct);
|
||||
await keySub.SetPublishingModeAsync(true, ct);
|
||||
|
||||
// Positive control: the still-granted session on the SAME folder channel gets the whole deferred tail.
|
||||
// Positive control: the still-granted session on the SAME folder gets the whole deferred tail.
|
||||
var lastNative = $"n{PerCondition - 1}";
|
||||
await RecordedEvents.WaitUntilAsync(() =>
|
||||
anonEvents.Has(anonA, lastNative) && anonEvents.Has(anonA, "after-revoke")
|
||||
|
||||
Reference in New Issue
Block a user