Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataHistoryDiagnosticsWireTests.cs
T
Joseph Doherty e3f21cb86c feat(grpc-data): H4 remote-history diagnostics and metrics
Consumer and origin history evidence for data connections (plan §6):
- DataConnectionHistoryDiagnostics: otopcua.dataconn.history.reads{variant,status_class,side} and
  otopcua.dataconn.history.continuations.active{side} on the exported OtOpcUa meter (the H2 origin
  counter sat on a private meter the host never exported); the plan's unknown-bits counter is the
  existing X0 otopcua.dataconnection.unknown_operations_dropped, reused
- per-connection projected answers by status class and open consumer continuations (settled on
  resume claim or release); origin sessions, open continuations and answers by status class
- negotiated features and advertised history variants/aggregates per connection
- AdminUI data-connections page renders them plus the dropped unknown-operation bits (#919)
- H4 unit-phase manifest key
2026-11-24 08:01:57 -05:00

86 lines
5.3 KiB
C#

using Opc.Ua;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
/// <summary>
/// H4 — the remote-history diagnostics follow real traffic: a real consumer OPC UA session reads a projected node through
/// the real projection stack and a real in-process origin; both sides' counts by status class and open continuations
/// move with each page, resume and release.
/// </summary>
public sealed partial class GrpcDataConfiguredDiscoveryWireTests
{
[Fact(Timeout = 90000)]
[Trait("Phase", "H4")]
public async Task History_diagnostics_count_answers_by_status_class_and_track_open_continuations_on_both_sides()
{
await using var originServer = await HistoryOrigin.StartAsync(7);
originServer.Source.Aggregates = new HashSet<HistoryAggregateType> { HistoryAggregateType.Average };
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
ProjectedHistoryAccess? history = null;
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
{
var client = (SessionClient)session;
await BrowseAll(client, anchor, 1);
var consumer = history!.Diagnostics;
// Before any history traffic: nothing counted, nothing open; the origin reports its backend.
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(0, 0, 0, 0));
var idle = origin.HistoryDiagnostics.CaptureOrigin().ShouldNotBeNull();
idle.Available.ShouldBeTrue();
(idle.ReadsGood, idle.ReadsBad, idle.OpenContinuations).ShouldBe((0L, 0L, 0));
// Page 1 of 7 at 2 per page: one Good answer on each side, one continuation open on each side.
var page = await RawHistory(client, anchor, 2, default);
page.ContinuationPoint.IsEmpty.ShouldBeFalse();
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(1, 0, 0, 1));
consumer.CaptureConsumer("LINK").Good.ShouldBe(1, "connection ids are case-insensitive");
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(1);
origin.HistoryDiagnostics.CaptureOrigin()!.ReadsGood.ShouldBe(1);
// Resume: the claimed cursor settles, its successor opens — still one open, two Good answers.
var next = await RawHistory(client, anchor, 2, page.ContinuationPoint);
next.ContinuationPoint.IsEmpty.ShouldBeFalse();
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(2, 0, 0, 1));
consumer.OpenConsumerContinuations.ShouldBe(1);
// releaseContinuationPoints: the consumer cursor settles at once, the origin's after the coalesced release.
await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(RawDetails(2)), TimestampsToReturn.Both, true,
[new HistoryReadValueId { NodeId = anchor, ContinuationPoint = next.ContinuationPoint }], TestContext.Current.CancellationToken);
consumer.CaptureConsumer("link").OpenContinuations.ShouldBe(0);
await AwaitReleases(history, () => origin.Services.HistoryOpenContinuations == 0);
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(0);
// An aggregate the origin refuses: one Bad answer on each side.
var refused = await ProcessedHistory(client, anchor, ObjectIds.AggregateFunction_Count);
refused.StatusCode.Code.ShouldBe(StatusCodes.BadAggregateNotSupported.Code);
consumer.CaptureConsumer("link").ShouldBe(new ConsumerHistoryCounts(2, 0, 1, 0));
var after = origin.HistoryDiagnostics.CaptureOrigin()!;
(after.ReadsGood, after.ReadsUncertain, after.ReadsBad).ShouldBe((2L, 0L, 1L));
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin), onHistory: (h, _) => history = h);
}
[Fact(Timeout = 90000)]
[Trait("Phase", "H4")]
public async Task Consumer_session_close_settles_its_open_consumer_continuations()
{
await using var originServer = await HistoryOrigin.StartAsync(7);
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
ProjectedHistoryAccess? history = null;
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
{
var client = (SessionClient)session;
await BrowseAll(client, anchor, 1);
(await RawHistory(client, anchor, 2, default)).ContinuationPoint.IsEmpty.ShouldBeFalse();
history!.Diagnostics.OpenConsumerContinuations.ShouldBe(1);
await session.CloseAsync(TestContext.Current.CancellationToken);
await AwaitReleases(history, () => origin.Services.HistoryOpenContinuations == 0);
history.Diagnostics.OpenConsumerContinuations.ShouldBe(0, "the SDK disposed the Remote point on session close");
origin.HistoryDiagnostics.CaptureOrigin()!.OpenContinuations.ShouldBe(0);
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin), onHistory: (h, _) => history = h);
}
}