Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataSdkSampleFidelityWireTests.cs
T
Joseph Doherty 62d9504868 fix(grpc-data): maxAge=0 projected reads served from an awaited origin read; origin refusals are access denials; Write/CreateMonitoredItems renew lapsed leases (#938, #939, #940)
#938: OtOpcUaNodeManager implements IReadAsyncNodeManager. A projected Value read whose maxAge the
cache cannot satisfy (0 always: Part 4 "read the source"; ScadaBridge's DCL and the Client CLI send
0) is served from IProjectedDataAccess.ReadNowAsync in the same request — same unary admission,
authenticated freshness-checked read and cache publication as ScheduleRead, pumped through the
unary budget, at most 5 s / request deadline − 250 ms, no Lock, no blocked thread. A lapsed lease
is renewed first and read in the same request. Previously every maxAge=0 read answered
BadWaitingForInitialData forever.

#939: RemoteNamespaceResolver.RenewExactOutcomeAsync reports Renewed/Refused/Failed. Refused only
for the origin's verdict (PERMISSION_DENIED call, Denied item, Metadata not granted, operation not
granted / not writable) ⇒ BadUserAccessDenied, held 5 s per node+operation unsent; transport and
other failures stay retryable. HistoryRead follows it.

#940: RenewLapsed accepts Write (gated on the local write role) and Subscribe. WriteAsync awaits the
renewal (≤ 4 s, ≤ half the timeout hint) then dispatches, BadResourceUnavailable unsent otherwise.
CreateMonitoredItems awaits renewals once per request (ICreateMonitoredItemsAsyncNodeManager) and
classifies each projected item PER ITEM outside Lock (lapse ⇒ BadResourceUnavailable, refusal ⇒
BadUserAccessDenied) — a refusal thrown from the item manager used to fault the whole request.

Red/green: 15 wire tests in GrpcDataProjectedOriginAccessWireTests (12 red on the pre-fix source,
controls green both ways); 4 existing tests updated where the first read is now Good. Evidence:
docs/plans/evidence/grpc-data-ext/938-939-940-948.md.
2026-12-01 19:55:49 -05:00

65 lines
3.5 KiB
C#

using System.Threading.Channels;
using Opc.Ua;
using Opc.Ua.Client;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
public sealed partial class GrpcDataConfiguredDiscoveryWireTests
{
[Fact(Timeout = 90000), Trait("Phase", "P10Wire")]
public async Task Sdk_mapped_read_preserves_one_controlled_samples_independent_timestamps_quality_value_and_version()
{
var ct = TestContext.Current.CancellationToken;
using var origin = new LocalDataFixture(servingGeneration: 1);
var sourceTime = origin.Clock.GetUtcNow().AddMinutes(-1).AddTicks(1234);
var serverTime = origin.Clock.GetUtcNow().AddSeconds(-30).AddTicks(5678);
const uint quality = 0x40A40480u;
const long version = 73;
origin.Hub.TryReserveIngress(origin.Ticket, 288, out var reservation).ShouldBeTrue();
using (reservation!)
{
var sample = new DataSample(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.DataValue.FromScalar(DataValueKind.Int32, 42), quality,
sourceTime, serverTime, origin.Serving, version);
if (!reservation!.TryCommit(sample, version))
{
sample.Dispose();
throw new InvalidOperationException("Controlled acquisition was not admitted.");
}
}
origin.Hub.ProcessPending();
var published = Channel.CreateUnbounded<ProjectedValueUpdate>();
await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) =>
{
var client = (SessionClient)session;
var children = await BrowseAll(client, anchor, 10);
var node = ExpandedNodeId.ToNodeId(children.Single(x => x.BrowseName.Name == "Speed").NodeId, session.NamespaceUris);
async Task<Opc.Ua.DataValue> ReadAsync()
{
var result = await client.ReadAsync(new RequestHeader(), 5000, TimestampsToReturn.Both,
[new ReadValueId { NodeId = node, AttributeId = Attributes.Value }], ct);
return result.Results[0];
}
// #938: the cold read is served from the origin read it triggers, in the same request — with the same fidelity.
var first = await ReadAsync();
first.WrappedValue.AsBoxedObject(Variant.BoxingBehavior.Legacy).ShouldBe(42);
first.StatusCode.Code.ShouldBe(quality);
first.SourceTimestamp.ShouldBe((DateTimeUtc)sourceTime.UtcDateTime);
first.ServerTimestamp.ShouldBe((DateTimeUtc)serverTime.UtcDateTime);
var admitted = await published.Reader.ReadAsync(ct).AsTask().WaitAsync(TimeSpan.FromSeconds(10), ct);
admitted.SourceVersion.ShouldBe(version);
admitted.Snapshot.StatusCode.ShouldBe(quality);
admitted.Snapshot.SourceTimestampUtc.ShouldBe(sourceTime.UtcDateTime);
admitted.Snapshot.ServerTimestampUtc.ShouldBe(serverTime.UtcDateTime);
var result = await ReadAsync();
result.WrappedValue.AsBoxedObject(Variant.BoxingBehavior.Legacy).ShouldBe(42);
result.StatusCode.Code.ShouldBe(quality);
result.SourceTimestamp.ShouldBe((DateTimeUtc)sourceTime.UtcDateTime);
result.ServerTimestamp.ShouldBe((DateTimeUtc)serverTime.UtcDateTime);
}, onPublished: value => published.Writer.TryWrite(value));
}
}