test(grpc-data): #922 review r1 — batch, crowd-out, slow-origin, revoked/removed/invalidated; docs + evidence

This commit is contained in:
Joseph Doherty
2026-11-28 10:58:12 -05:00
parent 7e924deda9
commit e076ceae64
3 changed files with 49 additions and 8 deletions
@@ -3,6 +3,7 @@ using Opc.Ua.Client;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
using ZB.MOM.WW.OtOpcUa.OpcUaServer;
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
using DataBrowseRequest = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.BrowseRequest;
using DataReadRequest = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ReadRequest;
@@ -172,6 +173,7 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
await using var originServer = await HistoryOrigin.StartAsync(7);
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
var connections = new GatedConnections(origin);
OtOpcUaNodeManager? manager = null;
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
{
var client = (SessionClient)session;
@@ -179,14 +181,25 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
origin.Clock.Advance(TimeSpan.FromSeconds(16));
connections.HoldMetadataFor = anchor.IdentifierAsString; // the origin never answers the renewal until released
var clock = System.Diagnostics.Stopwatch.StartNew();
var reads = Enumerable.Range(0, 24).Select(_ => RawHistory(client, anchor, 3, default)).ToArray();
async Task<(Opc.Ua.HistoryReadResult Result, TimeSpan Took)> Timed()
{
var each = System.Diagnostics.Stopwatch.StartNew();
var result = await RawHistory(client, anchor, 3, default);
return (result, each.Elapsed);
}
var reads = Enumerable.Range(0, 24).Select(_ => Timed()).ToArray();
var all = Task.WhenAll(reads);
// Every waiter is bounded (a non-local history slot, then at most the lapse wait) — none is pinned until the origin
// answers, which it never does while held.
(await Task.WhenAny(all, Task.Delay(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken))).ShouldBe(all,
"every concurrent HistoryRead returned while the origin was still silent");
clock.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(30));
var statuses = all.Result.Select(r => r.StatusCode.Code).ToArray();
var statuses = all.Result.Select(r => r.Result.StatusCode.Code).ToArray();
// Waiters are capped by the non-local history slots: the reads that found none answer at once instead of each pinning
// an SDK thread for the whole lapse wait (the pre-review code made all 24 wait it out).
var slots = OriginHistoryPort.RemoteSlots(manager!.MaxConcurrentHistoryReadBatches);
all.Result.Count(r => r.Took < TimeSpan.FromSeconds(2.5)).ShouldBeGreaterThanOrEqualTo(24 - slots,
string.Join(", ", all.Result.Select(r => r.Took.TotalMilliseconds.ToString("0"))));
statuses.ShouldAllBe(code => code == StatusCodes.BadResourceUnavailable.Code, "granted + lapsed + silent origin ⇒ retryable");
originServer.Source.Calls.ShouldBe(0);
@@ -200,7 +213,7 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
await Task.Delay(50, TestContext.Current.CancellationToken);
}
StatusCode.IsGood(served!.StatusCode).ShouldBeTrue(served.StatusCode.ToString());
}, localPermissions: 15, allowHistory: true, connectionSource: connections);
}, localPermissions: 15, allowHistory: true, connectionSource: connections, onHistory: (_, nm) => manager = nm);
}
/// <summary>One persistent origin connection whose metadata call for one node can be parked; counts browse/metadata/read calls.</summary>