fix(drivers): wire PollGroupEngine onError->health + 30s poll backoff (05/STAB-9) [modbus,abcip,ablegacy]
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// 05/STAB-9 — the poll engine's <c>onError</c> sink must be wired to the driver health
|
||||
/// surface: a poll-loop reader failure degrades health while preserving
|
||||
/// <see cref="DriverHealth.LastSuccessfulRead"/>, and must never downgrade a pre-existing
|
||||
/// <see cref="DriverState.Faulted"/>.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class AbLegacyPollErrorHealthTests
|
||||
{
|
||||
/// <summary>A poll reader failure degrades health, preserving the last successful read timestamp.</summary>
|
||||
[Fact]
|
||||
public async Task PollReaderFailure_DegradesHealth_PreservesLastSuccessfulRead()
|
||||
{
|
||||
var opts = new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
};
|
||||
var drv = new AbLegacyDriver(opts, "ablegacy-1", new FakeAbLegacyTagFactory());
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
var before = drv.GetHealth();
|
||||
before.State.ShouldBe(DriverState.Healthy);
|
||||
before.LastSuccessfulRead.ShouldNotBeNull();
|
||||
|
||||
drv.HandlePollError(new InvalidOperationException("poll boom"));
|
||||
|
||||
var after = drv.GetHealth();
|
||||
after.State.ShouldBe(DriverState.Degraded);
|
||||
after.LastSuccessfulRead.ShouldBe(before.LastSuccessfulRead);
|
||||
after.LastError.ShouldContain("poll boom");
|
||||
}
|
||||
|
||||
/// <summary>A poll reader failure never downgrades a pre-existing Faulted state.</summary>
|
||||
[Fact]
|
||||
public async Task PollReaderFailure_NeverDowngradesFaulted()
|
||||
{
|
||||
var opts = new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("not-a-valid-address")],
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
};
|
||||
var drv = new AbLegacyDriver(opts, "ablegacy-1", new FakeAbLegacyTagFactory());
|
||||
|
||||
await Should.ThrowAsync<Exception>(() => drv.InitializeAsync("{}", CancellationToken.None));
|
||||
drv.GetHealth().State.ShouldBe(DriverState.Faulted);
|
||||
|
||||
drv.HandlePollError(new InvalidOperationException("poll boom"));
|
||||
|
||||
drv.GetHealth().State.ShouldBe(DriverState.Faulted);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user