7829b937d1
OpcUa:Redundancy:Mode (Unset default = today's server exactly; None; Warm; Hot and unknown values fail start). - T1 options + validator + effective-URI check + boot banner; Warm needs the driver role. - T2 metadata in OnNodeManagerStartedAsync: Warm -> NonTransparentRedundancyType, read-only ServerUriArray [self, peers], RedundancySupport=Warm, boot ServiceLevel 1; None -> RedundancySupport=None and the SDK's orphan i=11314 deleted; Unset untouched. - T3 RedundancyStateChanged.Revision (up-number, incarnation tick, sequence); subscribers drop older revisions under Warm (OpcUaPublishActor, DriverHostActor); unrevisioned never makes a node Active. - T4 WarmRoleAuthority + ComputeWarm bands (Standby 90/50, Active 250/200/100), PromoteWhilePrimaryUnreachable. - T5 IStandbyProjection + DeferredStandbyProjection; OpcUaPublishActor runs promotion/demotion in the spec 4.7 order (Active level last and retried; Standby level first, data degraded regardless). - T6 EquipmentVariableState read projection (BadOutOfService/null); Warm Standby refuses writes BadInvalidState. - T7 D4 mechanism adopted after T0: ordinary-tag marker on MonitoredItemNotification.Message validated by (ClientHandle, DataValue); first-delivery decision keyed by (SubscriptionId, SequenceNumber); the SDK's cached copy is never mutated. - T8 queue current/BadOutOfService to live ordinary-tag items ignoring filters. - T9 alarm stamp/deliver split (suppressed on Standby), Part 9 methods refused on Standby, promotion refresh via ISubscription.ConditionRefresh2Async on every live event item. - T10 deploy-time RedundancyMode cross-check + six instruments. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
92 lines
4.5 KiB
C#
92 lines
4.5 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.Redundancy;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Redundancy;
|
|
|
|
/// <summary>Gitea #717 spec §4.1: the Warm verdict truth table, and the late-bound projection's replay (spec §4.7).</summary>
|
|
public sealed class WarmRoleAuthorityTests
|
|
{
|
|
private static readonly NodeId Self = NodeId.Parse("a:1");
|
|
private static readonly NodeId Peer = NodeId.Parse("b:1");
|
|
|
|
private static WarmRoleInputs In(NodeId? oldest = null, NodeId? oldestReachable = null, bool hasSnapshot = true,
|
|
NodeId? snapshotPrimary = null, bool primaryUnreachable = false, bool promote = true, bool up = true, bool listening = true) =>
|
|
new(Self, up, listening, oldest, oldestReachable ?? oldest, hasSnapshot, snapshotPrimary, primaryUnreachable, promote);
|
|
|
|
[Fact]
|
|
public void Active_iff_membership_and_the_accepted_snapshot_both_name_self()
|
|
{
|
|
WarmRoleAuthority.Evaluate(In(oldest: Self, snapshotPrimary: Self)).Role.ShouldBe(WarmRole.Active);
|
|
WarmRoleAuthority.Evaluate(In(oldest: Peer, snapshotPrimary: Peer)).Role.ShouldBe(WarmRole.Standby);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void Any_disagreement_is_Standby_and_flagged(bool membershipSaysSelf)
|
|
{
|
|
var verdict = WarmRoleAuthority.Evaluate(In(oldest: membershipSaysSelf ? Self : Peer, snapshotPrimary: membershipSaysSelf ? Peer : Self));
|
|
verdict.Role.ShouldBe(WarmRole.Standby);
|
|
verdict.Disagreement.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Boot_with_no_accepted_snapshot_is_Standby_whatever_the_membership()
|
|
{
|
|
var verdict = WarmRoleAuthority.Evaluate(In(oldest: Self, hasSnapshot: false, snapshotPrimary: null));
|
|
verdict.Role.ShouldBe(WarmRole.Standby);
|
|
verdict.Reason.ShouldBe("boot");
|
|
}
|
|
|
|
[Fact]
|
|
public void Not_up_or_endpoint_failed_is_Standby()
|
|
{
|
|
WarmRoleAuthority.Evaluate(In(oldest: Self, snapshotPrimary: Self, up: false)).Role.ShouldBe(WarmRole.Standby);
|
|
WarmRoleAuthority.Evaluate(In(oldest: Self, snapshotPrimary: Self, listening: false)).Role.ShouldBe(WarmRole.Standby);
|
|
}
|
|
|
|
/// <summary>Owner answer Q2: a crashed Primary stays Up-but-unreachable until auto-down; the survivor promotes.</summary>
|
|
[Fact]
|
|
public void The_survivor_promotes_while_the_Primary_is_unreachable_only_with_the_option()
|
|
{
|
|
var crashed = In(oldest: Peer, oldestReachable: Self, snapshotPrimary: Peer, primaryUnreachable: true);
|
|
WarmRoleAuthority.Evaluate(crashed).Role.ShouldBe(WarmRole.Active);
|
|
WarmRoleAuthority.Evaluate(crashed with { PromoteWhilePrimaryUnreachable = false }).Role.ShouldBe(WarmRole.Standby);
|
|
WarmRoleAuthority.Evaluate(crashed with { SnapshotPrimaryUnreachable = false }).Role.ShouldBe(WarmRole.Standby,
|
|
"a reachable Primary is never overridden");
|
|
WarmRoleAuthority.Evaluate(crashed with { HasAcceptedSnapshot = false, SnapshotPrimary = null }).Role
|
|
.ShouldBe(WarmRole.Standby, "a node that never accepted a snapshot stays Standby");
|
|
}
|
|
|
|
[Fact]
|
|
public void A_late_bind_replays_the_retained_state_but_not_the_actions()
|
|
{
|
|
var deferred = new DeferredStandbyProjection();
|
|
deferred.SetDataProjection(false);
|
|
deferred.SetStandbyDelivery(false);
|
|
deferred.SetAlarmSuppression(false);
|
|
deferred.QueueCurrentToLiveItems(false).ShouldBe(0);
|
|
deferred.RefreshAllEventItems().ShouldBe(0);
|
|
|
|
var inner = new RecordingProjection();
|
|
deferred.SetInner(inner);
|
|
inner.Log.ShouldBe(new[] { "proj:False", "delivery:False", "alarms:False" });
|
|
deferred.QueueCurrentToLiveItems(true);
|
|
inner.Log.Last().ShouldBe("queue:True");
|
|
}
|
|
}
|
|
|
|
/// <summary>Records every <see cref="IStandbyProjection"/> step into a shared, ordered log.</summary>
|
|
internal sealed class RecordingProjection(System.Collections.Concurrent.ConcurrentQueue<string>? log = null) : IStandbyProjection
|
|
{
|
|
public System.Collections.Concurrent.ConcurrentQueue<string> Log { get; } = log ?? new();
|
|
public void SetDataProjection(bool projected) => Log.Enqueue($"proj:{projected}");
|
|
public void SetStandbyDelivery(bool standby) => Log.Enqueue($"delivery:{standby}");
|
|
public void SetAlarmSuppression(bool suppressed) => Log.Enqueue($"alarms:{suppressed}");
|
|
public int QueueCurrentToLiveItems(bool projected) { Log.Enqueue($"queue:{projected}"); return 1; }
|
|
public int RefreshAllEventItems() { Log.Enqueue("refresh"); return 1; }
|
|
}
|