Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataHistoryDiagnosticsDisplayTests.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

59 lines
2.9 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections;
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.DataConnections;
/// <summary>H4 diagnostics display (plan §6) and the X0 dropped-bit rendering (#919) on the data-connections page.</summary>
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H4")]
public sealed class GrpcDataHistoryDiagnosticsDisplayTests
{
private static DataConnectionDiagnosticsSnapshot Row() =>
new("link", 1, "ready", null, null, 0, 0, 1, "artifact", DateTime.UtcNow);
[Fact]
public void Negotiated_features_distinguish_unavailable_v1_and_history()
{
DataConnectionDiagnostics.Features(null).ShouldBe("unavailable");
DataConnectionDiagnostics.Features(DataFeatures.None).ShouldBe("none (v1 behaviour)");
DataConnectionDiagnostics.Features(DataFeatures.History).ShouldBe("History");
DataConnectionDiagnostics.Features(DataFeatures.History | DataFeatures.Conditions).ShouldBe("History, Conditions");
}
[Fact]
public void Origin_history_shows_the_advertised_variants_and_aggregate_count()
{
DataConnectionDiagnostics.HistoryServed(Row()).ShouldBe("not advertised");
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = [] }).ShouldBe("advertised, no variant granted");
DataConnectionDiagnostics.HistoryServed(Row() with { HistoryVariants = ["raw", "processed", "attime"], HistoryAggregateCount = 12 })
.ShouldBe("raw, processed, attime (12 aggregates)");
}
[Fact]
public void History_counts_by_status_class_are_unavailable_from_an_older_node_not_zero()
{
DataConnectionDiagnostics.HistoryCounts(null, null, null).ShouldBe("unavailable");
DataConnectionDiagnostics.HistoryCounts(5, 0, 2).ShouldBe("good 5 · uncertain 0 · bad 2");
}
[Fact]
public void Dropped_bits_are_named_when_known_and_hex_when_not()
{
DataConnectionDiagnostics.DroppedBits(null).ShouldBe("unavailable");
DataConnectionDiagnostics.DroppedBits(DataOperations.None).ShouldBe("none");
DataConnectionDiagnostics.DroppedBits(DataOperations.HistoryRead | DataOperations.AlarmSubscribe).ShouldBe("HistoryRead, AlarmSubscribe");
DataConnectionDiagnostics.DroppedBits((DataOperations)(1 << 20)).ShouldBe("0x100000");
}
[Fact]
public void The_older_build_hint_shows_only_when_something_was_dropped()
{
DataConnectionDiagnostics.HasDrops(null).ShouldBeFalse();
DataConnectionDiagnostics.HasDrops(DataOperations.None, 0).ShouldBeFalse();
DataConnectionDiagnostics.HasDrops(DataOperations.HistoryRead).ShouldBeTrue();
DataConnectionDiagnostics.HasDrops(DataOperations.None, 2).ShouldBeTrue("a mapping's drop counts even when the connection dropped none");
}
}