Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Drivers/ChildHealthLedgerTests.cs
T

45 lines
1.7 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
/// <summary>R-16: a stopped child's late health publish must not resurrect its ledger entry.</summary>
public sealed class ChildHealthLedgerTests
{
private sealed class CountingPublisher : IDriverHealthPublisher
{
public int Count;
public void Publish(
string clusterId, string driverInstanceId, DriverHealth health, int errorCount5Min,
DateTime? rediscoveryNeededUtc = null, string? rediscoveryReason = null,
IReadOnlyList<HostConnectivityStatus>? hostStatuses = null, SkippedTagReport? skippedTags = null,
IReadOnlyDictionary<string, string>? diagnostics = null) => Count++;
}
private static void Publish(ChildHealthLedger ledger, string id) =>
ledger.Publish("c1", id, new DriverHealth(DriverState.Healthy, DateTime.UtcNow, null), 0);
[Fact]
public void A_late_publish_after_Forget_is_forwarded_but_not_recorded_until_Readmit()
{
var inner = new CountingPublisher();
var ledger = new ChildHealthLedger(inner);
Publish(ledger, "d1");
ledger.TryGet("d1").ShouldNotBeNull(); // positive control: the ledger records when not held
ledger.Forget("d1");
ledger.TryGet("d1").ShouldBeNull();
Publish(ledger, "d1"); // the stopping child's late publish
ledger.TryGet("d1").ShouldBeNull();
inner.Count.ShouldBe(2); // still forwarded — the hub tombstones its own side
ledger.Readmit("d1"); // a new child of the id spawns
Publish(ledger, "d1");
ledger.TryGet("d1").ShouldNotBeNull();
}
}