Files
lmxopcua/tests/ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.IntegrationTests/AbLegacyDiagnosticsIntegrationTests.cs
2026-04-26 03:50:47 -04:00

57 lines
2.4 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.IntegrationTests;
/// <summary>
/// PR ablegacy-10 / #253 — wire-level smoke against ab_server PCCC: after N reads
/// against the live runtime, the auto-emitted <c>_Diagnostics/&lt;host&gt;/RequestCount</c>
/// short-circuit must round-trip the same N value through <c>ReadAsync</c>. Skipped
/// when ab_server isn't reachable; otherwise builds the same way the existing read
/// smoke tests do.
/// </summary>
[Collection(AbLegacyServerCollection.Name)]
[Trait("Category", "Integration")]
[Trait("Simulator", "ab_server-PCCC")]
public sealed class AbLegacyDiagnosticsIntegrationTests(AbLegacyServerFixture sim)
{
[AbLegacyFact]
public async Task RequestCount_diagnostic_matches_read_invocations()
{
if (sim.SkipReason is not null) Assert.Skip(sim.SkipReason);
var deviceUri = $"ab://{sim.Host}:{sim.Port}/{sim.CipPath}";
await using var drv = new AbLegacyDriver(new AbLegacyDriverOptions
{
Devices = [new AbLegacyDeviceOptions(deviceUri, AbLegacyPlcFamily.Slc500)],
Tags =
[
new AbLegacyTagDefinition(
Name: "IntCounter",
DeviceHostAddress: deviceUri,
Address: "N7:0",
DataType: AbLegacyDataType.Int),
],
Timeout = TimeSpan.FromSeconds(5),
Probe = new AbLegacyProbeOptions { Enabled = false },
}, driverInstanceId: "ablegacy-smoke-diagnostics");
await drv.InitializeAsync("{}", TestContext.Current.CancellationToken);
const int N = 5;
for (var i = 0; i < N; i++)
await drv.ReadAsync(["IntCounter"], TestContext.Current.CancellationToken);
// Diagnostic short-circuit returns the live counter through ReadAsync without a
// libplctag round-trip. Verifies both that the discovery path emitted the
// address + that the read path serves it locally with Good status.
var diagRef = $"{AbLegacyDiagnosticTags.DiagnosticsFolderPrefix}{deviceUri}/RequestCount";
var snapshots = await drv.ReadAsync([diagRef], TestContext.Current.CancellationToken);
snapshots.Single().StatusCode.ShouldBe(AbLegacyStatusMapper.Good);
Convert.ToInt64(snapshots.Single().Value).ShouldBe(N);
}
}