fix(ablegacy): libplctag refuses MicroLogix function files locally instead of a comms fault (#592)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
libplctag 2.6.0 cannot parse RTC/HSC/... names; tag creation failed with PLCTAG_ERR_BAD_PARAM, which the status translation reported as BadConnection: evicted handle, degraded health, counted toward marking a healthy device down. The libplctag runtime now refuses function-file addresses before creating a native tag (Unsupported -> BadNotSupported, health untouched), matching native. Docs: function files are unsupported on both transports, not "unverified". Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// #592 (2026-11-13): libplctag 2.6.0 cannot parse a MicroLogix function-file name (<c>RTC:0.HR</c>, <c>HSC:0.ACC</c>),
|
||||
/// so its tag creation failed locally with <c>PLCTAG_ERR_BAD_PARAM</c> — translated to <see cref="AbStatus.BadConnection"/>,
|
||||
/// i.e. a comms fault that evicted the handle, degraded health and counted toward marking the device down. The libplctag
|
||||
/// runtime now refuses these addresses before creating a native tag, as the native transport already did.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class LibplctagFunctionFileRefusalTests
|
||||
{
|
||||
private static AbLegacyTagCreateParams Params(string tag) =>
|
||||
new("192.0.2.1", 44818, "", "micrologix", tag, TimeSpan.FromSeconds(1));
|
||||
|
||||
[Theory]
|
||||
[InlineData("RTC:0.HR", true)]
|
||||
[InlineData("RTC:0.YR", true)]
|
||||
[InlineData("HSC:0.ACC", true)]
|
||||
[InlineData("DLS:0.EN", true)]
|
||||
[InlineData("BHI:0.OS", true)]
|
||||
[InlineData("STI:0.EN", true)]
|
||||
[InlineData("N7:0", false)]
|
||||
[InlineData("R6:0.LEN", false)]
|
||||
[InlineData("ST14:0", false)]
|
||||
[InlineData("S:0", false)]
|
||||
public void Only_function_files_are_refused(string tag, bool refused)
|
||||
{
|
||||
(LibplctagLegacyTagRuntime.Refusal(Params(tag)) is not null).ShouldBe(refused);
|
||||
if (refused) LibplctagLegacyTagRuntime.WriteRefusal(Params(tag)).ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Init, read and write all refuse without touching the network (the gateway is unroutable, the timeout 1 s).</summary>
|
||||
[Fact]
|
||||
public async Task The_runtime_refuses_every_operation_before_the_wire()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
using var rt = new LibplctagLegacyTagRuntime(Params("RTC:0.HR"));
|
||||
rt.IsRefused.ShouldBeTrue();
|
||||
(await Should.ThrowAsync<AbTransportException>(() => rt.InitializeAsync(ct))).Status.ShouldBe(AbStatus.Unsupported);
|
||||
(await Should.ThrowAsync<AbTransportException>(() => rt.ReadAsync(ct))).Status.ShouldBe(AbStatus.Unsupported);
|
||||
(await Should.ThrowAsync<AbTransportException>(() => rt.WriteAsync(ct))).Status.ShouldBe(AbStatus.Unsupported);
|
||||
rt.NativeHandle.ShouldBe(0, "no native libplctag tag is ever created for a refused address");
|
||||
}
|
||||
|
||||
#pragma warning disable OTOPCUA0001 // direct driver calls pin the driver's own status mapping (no resilience wrapper)
|
||||
/// <summary>Through the production libplctag factory: BadNotSupported, health unchanged.</summary>
|
||||
[Fact]
|
||||
public async Task A_function_file_read_on_libplctag_is_BadNotSupported_with_health_unchanged()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
const string host = "ab://192.0.2.1/";
|
||||
var driver = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions(host, AbLegacyPlcFamily.MicroLogix)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Hr", host, "RTC:0.HR", AbLegacyDataType.Int)]),
|
||||
Timeout = TimeSpan.FromSeconds(1),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
Transport = AbLegacyTransport.Libplctag,
|
||||
}, "drv-libplctag-function-file", new LibplctagLegacyTagFactory());
|
||||
await driver.InitializeAsync("{}", ct);
|
||||
var health = driver.GetHealth();
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
(await driver.ReadAsync(["Hr"], ct)).Single().StatusCode.ShouldBe(AbLegacyStatusMapper.BadNotSupported);
|
||||
|
||||
driver.GetHealth().ShouldBe(health);
|
||||
await driver.ShutdownAsync(ct);
|
||||
}
|
||||
#pragma warning restore OTOPCUA0001
|
||||
}
|
||||
Reference in New Issue
Block a user