Merge review fixes: superseded deployment's ack write no longer drops successor's ack (#996); degraded-apply repair re-pushes drivers (#995)
This commit is contained in:
+198
@@ -0,0 +1,198 @@
|
||||
using Akka.Actor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Deploy;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane.Coordinators;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane.Tests.Harness;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// #996 x #977 (H-4) review: in-flight ack writes were tracked by NODE only, and <c>ResetForNext</c> (supersede,
|
||||
/// every terminal path) cleared the parked-behind acks but not the in-flight set. So with deployment A's ack write
|
||||
/// for node N still running, B superseding A and N acking B parked B's ack behind A's write — and when A's write
|
||||
/// came back as stale it deleted B's parked ack. B then timed out naming N, though N had applied it.
|
||||
/// </summary>
|
||||
public sealed class ConfigPublishCoordinatorSupersededAckWriteTests : ControlPlaneActorTestBase
|
||||
{
|
||||
private static readonly RevisionHash RevA = RevisionHash.Parse(new string('a', 64));
|
||||
private static readonly RevisionHash RevB = RevisionHash.Parse(new string('b', 64));
|
||||
private const string Node = "site-a-1:4053";
|
||||
|
||||
/// <summary>The successor's ack must land and seal it, though the superseded deployment's write for that node is still running.</summary>
|
||||
[Fact]
|
||||
public async Task Successor_ack_seals_while_the_superseded_deployments_write_for_that_node_is_in_flight()
|
||||
{
|
||||
var (direct, gated) = NewFactories();
|
||||
SeedNode(direct);
|
||||
var a = SeedDispatching(direct, RevA);
|
||||
var actor = Sys.ActorOf(ConfigPublishCoordinator.Props(gated, TimeSpan.FromMinutes(5)));
|
||||
actor.Tell(new DispatchDeployment(a, RevA, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, a, DeploymentStatus.AwaitingApplyAcks);
|
||||
|
||||
// A's ack write for N blocks on the pool until released.
|
||||
gated.ArmOnce();
|
||||
actor.Tell(Ack(a));
|
||||
gated.Entered.Wait(PresenceBudget, TestContext.Current.CancellationToken).ShouldBeTrue("A's ack write never started");
|
||||
|
||||
var b = SeedDispatching(direct, RevB);
|
||||
actor.Tell(new DispatchDeployment(b, RevB, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, a, DeploymentStatus.TimedOut);
|
||||
AwaitStatus(direct, b, DeploymentStatus.AwaitingApplyAcks);
|
||||
|
||||
actor.Tell(Ack(b));
|
||||
// Make sure B's ack is processed BEFORE A's stale write returns (the order that dropped it).
|
||||
await actor.Ask<ActorIdentity>(new Identify(null), PresenceBudget, TestContext.Current.CancellationToken);
|
||||
gated.Release();
|
||||
|
||||
AwaitStatus(direct, b, DeploymentStatus.Sealed);
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
using var db = direct.CreateDbContext();
|
||||
db.NodeDeploymentStates.Single(s => s.DeploymentId == b.Value).Status.ShouldBe(NodeDeploymentStatus.Applied);
|
||||
}, duration: PresenceBudget, cancellationToken: TestContext.Current.CancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same defect via the deferral cap: A closes from memory with its write still running (the cap path never removed
|
||||
/// the in-flight entry), and B's ack for that node must still land before B's own deadline.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Successor_ack_seals_after_the_prior_deployment_closed_at_the_deferral_cap_with_a_write_running()
|
||||
{
|
||||
var (direct, gated) = NewFactories();
|
||||
SeedNode(direct);
|
||||
var a = SeedDispatching(direct, RevA);
|
||||
// Deadline 2 s; the deferral cap is 10 x 50 ms = 500 ms past it.
|
||||
var actor = Sys.ActorOf(ConfigPublishCoordinator.Props(
|
||||
gated, TimeSpan.FromSeconds(2),
|
||||
loadRetryMin: TimeSpan.FromMilliseconds(20), loadRetryMax: TimeSpan.FromMilliseconds(50)));
|
||||
actor.Tell(new DispatchDeployment(a, RevA, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, a, DeploymentStatus.AwaitingApplyAcks);
|
||||
|
||||
gated.ArmOnce();
|
||||
actor.Tell(Ack(a));
|
||||
gated.Entered.Wait(PresenceBudget, TestContext.Current.CancellationToken).ShouldBeTrue("A's ack write never started");
|
||||
// The deadline defers on the in-flight write, hits the cap, and decides A from memory (sealed: N did ack).
|
||||
AwaitStatus(direct, a, DeploymentStatus.Sealed);
|
||||
|
||||
var b = SeedDispatching(direct, RevB);
|
||||
actor.Tell(new DispatchDeployment(b, RevB, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, b, DeploymentStatus.AwaitingApplyAcks);
|
||||
actor.Tell(Ack(b));
|
||||
await actor.Ask<ActorIdentity>(new Identify(null), PresenceBudget, TestContext.Current.CancellationToken);
|
||||
gated.Release();
|
||||
|
||||
AwaitStatus(direct, b, DeploymentStatus.Sealed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Positive control: the successor's ack arriving AFTER the superseded deployment's write has returned seals it —
|
||||
/// the harness (gate, supersede, in-memory DB) can seal B, so the tests above fail only on the dropped ack.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Control_successor_ack_after_the_superseded_write_returned_seals()
|
||||
{
|
||||
var (direct, gated) = NewFactories();
|
||||
SeedNode(direct);
|
||||
var a = SeedDispatching(direct, RevA);
|
||||
var actor = Sys.ActorOf(ConfigPublishCoordinator.Props(gated, TimeSpan.FromMinutes(5)));
|
||||
actor.Tell(new DispatchDeployment(a, RevA, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, a, DeploymentStatus.AwaitingApplyAcks);
|
||||
|
||||
gated.ArmOnce();
|
||||
actor.Tell(Ack(a));
|
||||
gated.Entered.Wait(PresenceBudget, TestContext.Current.CancellationToken).ShouldBeTrue("A's ack write never started");
|
||||
|
||||
var b = SeedDispatching(direct, RevB);
|
||||
actor.Tell(new DispatchDeployment(b, RevB, CorrelationId.NewId()));
|
||||
AwaitStatus(direct, b, DeploymentStatus.AwaitingApplyAcks);
|
||||
gated.Release();
|
||||
// A's (stale) write lands its row...
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
using var db = direct.CreateDbContext();
|
||||
db.NodeDeploymentStates.Single(s => s.DeploymentId == a.Value).Status.ShouldBe(NodeDeploymentStatus.Applied);
|
||||
}, duration: PresenceBudget, cancellationToken: TestContext.Current.CancellationToken);
|
||||
// ...but the superseded deployment stays closed.
|
||||
AwaitStatus(direct, a, DeploymentStatus.TimedOut);
|
||||
|
||||
actor.Tell(Ack(b));
|
||||
AwaitStatus(direct, b, DeploymentStatus.Sealed);
|
||||
}
|
||||
|
||||
private static ApplyAck Ack(DeploymentId id) =>
|
||||
new(id, NodeId.Parse(Node), ApplyAckOutcome.Applied, null, CorrelationId.NewId());
|
||||
|
||||
private static (IDbContextFactory<OtOpcUaConfigDbContext> Direct, GatedFactory Gated) NewFactories()
|
||||
{
|
||||
var name = Guid.NewGuid().ToString("N");
|
||||
return (NewInMemoryDbFactory(name), new GatedFactory(NewInMemoryDbFactory(name)));
|
||||
}
|
||||
|
||||
private void AwaitStatus(IDbContextFactory<OtOpcUaConfigDbContext> f, DeploymentId id, DeploymentStatus expected) =>
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
using var db = f.CreateDbContext();
|
||||
db.Deployments.Single(d => d.DeploymentId == id.Value).Status.ShouldBe(expected);
|
||||
}, duration: PresenceBudget, cancellationToken: TestContext.Current.CancellationToken);
|
||||
|
||||
private static void SeedNode(IDbContextFactory<OtOpcUaConfigDbContext> f)
|
||||
{
|
||||
using var db = f.CreateDbContext();
|
||||
db.ServerClusters.Add(new ServerCluster
|
||||
{
|
||||
ClusterId = "SITE-A", Name = "Site A", Enterprise = "zb", Site = "site-a", NodeCount = 1,
|
||||
RedundancyMode = RedundancyMode.None, CreatedBy = "test",
|
||||
});
|
||||
db.ClusterNodes.Add(new ClusterNode
|
||||
{
|
||||
NodeId = Node, ClusterId = "SITE-A", Host = "site-a-1", ApplicationUri = $"urn:OtOpcUa:{Node}",
|
||||
Enabled = true, CreatedBy = "test",
|
||||
});
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
private static DeploymentId SeedDispatching(IDbContextFactory<OtOpcUaConfigDbContext> f, RevisionHash rev)
|
||||
{
|
||||
var id = DeploymentId.NewId();
|
||||
using var db = f.CreateDbContext();
|
||||
db.Deployments.Add(new Deployment
|
||||
{
|
||||
DeploymentId = id.Value, RevisionHash = rev.Value, Status = DeploymentStatus.Dispatching, CreatedBy = "test",
|
||||
});
|
||||
db.SaveChanges();
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A factory whose NEXT context creation after <see cref="ArmOnce"/> blocks (on the pool thread running the ack
|
||||
/// write) until <see cref="Release"/>; every other creation passes straight through.
|
||||
/// </summary>
|
||||
private sealed class GatedFactory(IDbContextFactory<OtOpcUaConfigDbContext> inner) : IDbContextFactory<OtOpcUaConfigDbContext>
|
||||
{
|
||||
private readonly ManualResetEventSlim _release = new(false);
|
||||
private int _armed;
|
||||
|
||||
public ManualResetEventSlim Entered { get; } = new(false);
|
||||
|
||||
public void ArmOnce() => Interlocked.Exchange(ref _armed, 1);
|
||||
|
||||
public void Release() => _release.Set();
|
||||
|
||||
public OtOpcUaConfigDbContext CreateDbContext()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _armed, 0) == 1)
|
||||
{
|
||||
Entered.Set();
|
||||
_release.Wait(TimeSpan.FromSeconds(60));
|
||||
}
|
||||
return inner.CreateDbContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
using Akka.Actor;
|
||||
using Akka.TestKit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Engines;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Deploy;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
|
||||
|
||||
/// <summary>
|
||||
/// #995 R-11 x #977 R-4 review, against a REAL <see cref="OpcUaPublishActor"/> (the R-11 tests stub it, so they
|
||||
/// cannot see this). A degraded apply fails to create a node; the driver host's post-degraded re-push runs while the
|
||||
/// node is still missing (writes are non-creating, so its value goes nowhere). The NEXT apply creates the node — but
|
||||
/// the driver's seeding fingerprint is unchanged, so the deploy skipped it, and the publish actor reported a clean
|
||||
/// non-rebuild. The node stayed BadWaitingForInitialData until the value changed (forever for a constant).
|
||||
/// </summary>
|
||||
[Collection("opcua-publish-meters")]
|
||||
public sealed class DriverHostActorDegradedRepairReseedTests : RuntimeActorTestBase
|
||||
{
|
||||
private static readonly NodeId TestNode = NodeId.Parse("node-1:4053");
|
||||
private const string PressurePath = "Plant/Modbus2/dev2/pressure";
|
||||
|
||||
private static readonly (string, string, string, string, string, bool)[] OneDriver =
|
||||
[("drv-1", "Modbus", "dev1", "speed", "Float", false)];
|
||||
|
||||
private static readonly (string, string, string, string, string, bool)[] TwoDrivers =
|
||||
[("drv-1", "Modbus", "dev1", "speed", "Float", false), ("drv-2", "Modbus2", "dev2", "pressure", "Float", false)];
|
||||
|
||||
// drv-1's driver folder renamed: a raw CONTAINER rename, which is a full rebuild; drv-2 is untouched by it.
|
||||
private static readonly (string, string, string, string, string, bool)[] TwoDriversRenamed =
|
||||
[("drv-1", "ModbusRenamed", "dev1", "speed", "Float", false), ("drv-2", "Modbus2", "dev2", "pressure", "Float", false)];
|
||||
|
||||
private static readonly (string, string, string, string, string, bool)[] ThreeDriversRenamed =
|
||||
[
|
||||
("drv-1", "ModbusRenamed", "dev1", "speed", "Float", false), ("drv-2", "Modbus2", "dev2", "pressure", "Float", false),
|
||||
("drv-3", "Modbus3", "dev3", "flow", "Float", false),
|
||||
];
|
||||
|
||||
private static readonly (string, string, string, string, string?)[] NoRefs = [];
|
||||
|
||||
/// <summary>Degraded NON-rebuild (composition held back), then the re-diff creates the node: its driver is re-pushed.</summary>
|
||||
[Fact]
|
||||
public void A_node_a_degraded_add_failed_to_create_gets_its_driver_re_pushed_when_the_next_apply_creates_it()
|
||||
{
|
||||
var rig = new Rig(this, NewInMemoryDbFactory());
|
||||
rig.Deploy(OneDriver, Rev('a'));
|
||||
AwaitAssert(() => rig.Driver("drv-1").SubscribeCount.ShouldBe(1), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
// B adds drv-2; its pressure variable cannot be created ⇒ degraded, drv-2 pushed with its node missing.
|
||||
rig.Sink.FailVariable = PressurePath;
|
||||
rig.Deploy(TwoDrivers, Rev('b'), expectDegraded: true);
|
||||
var drv2 = rig.Driver("drv-2");
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(1), PresenceBudget, cancellationToken: Ct);
|
||||
rig.Sink.CreatedVariables.ShouldNotContain(PressurePath);
|
||||
|
||||
// C (same composition, fault gone) creates the node. drv-2's fingerprint is unchanged, so the deploy skips it —
|
||||
// the outcome must still re-push it, or the new node never gets a value.
|
||||
rig.Sink.FailVariable = null;
|
||||
rig.Deploy(TwoDrivers, Rev('c'));
|
||||
rig.Sink.CreatedVariables.ShouldContain(PressurePath);
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(2), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
// Positive control: the address space is clean again, so a further unrelated deploy skips drv-2 as before.
|
||||
rig.Deploy(ThreeDriversWith(drv1Name: "Modbus"), Rev('d'));
|
||||
AwaitAssert(() => rig.Driver("drv-3").SubscribeCount.ShouldBe(1), PresenceBudget, cancellationToken: Ct);
|
||||
Thread.Sleep(300);
|
||||
drv2.SubscribeCount.ShouldBe(2, "a clean non-rebuild deploy after the repair must still skip the untouched driver");
|
||||
}
|
||||
|
||||
/// <summary>Degraded REBUILD (composition advanced), then the empty-plan repair of the same revision creates the node.</summary>
|
||||
[Fact]
|
||||
public void A_node_a_degraded_rebuild_failed_to_create_gets_its_driver_re_pushed_by_the_empty_plan_repair()
|
||||
{
|
||||
var rig = new Rig(this, NewInMemoryDbFactory());
|
||||
rig.Deploy(TwoDrivers, Rev('a'));
|
||||
var drv2 = rig.Driver("drv-2");
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(1), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
rig.Sink.FailVariable = PressurePath;
|
||||
rig.Deploy(TwoDriversRenamed, Rev('b'), expectDegraded: true);
|
||||
rig.Sink.RebuildCount.ShouldBe(1);
|
||||
// drv-2 was skipped, then re-pushed on the degraded outcome — while its node is missing.
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(2), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
rig.Sink.FailVariable = null;
|
||||
var created = rig.Sink.CreatedVariables.Count(v => v == PressurePath);
|
||||
rig.Deploy(TwoDriversRenamed, Rev('c')); // same composition ⇒ empty plan ⇒ the repair branch
|
||||
rig.Sink.CreatedVariables.Count(v => v == PressurePath).ShouldBeGreaterThan(created);
|
||||
rig.Sink.RebuildCount.ShouldBe(1, "the repair must not need a rebuild");
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(3), PresenceBudget, cancellationToken: Ct);
|
||||
}
|
||||
|
||||
/// <summary>Degraded REBUILD, then an UNRELATED add re-ensures the whole composition (#977 R-4) and creates the node.</summary>
|
||||
[Fact]
|
||||
public void A_node_a_degraded_rebuild_failed_to_create_gets_its_driver_re_pushed_by_the_R4_whole_composition_repair()
|
||||
{
|
||||
var rig = new Rig(this, NewInMemoryDbFactory());
|
||||
rig.Deploy(TwoDrivers, Rev('a'));
|
||||
var drv2 = rig.Driver("drv-2");
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(1), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
rig.Sink.FailVariable = PressurePath;
|
||||
rig.Deploy(TwoDriversRenamed, Rev('b'), expectDegraded: true);
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(2), PresenceBudget, cancellationToken: Ct);
|
||||
|
||||
rig.Sink.FailVariable = null;
|
||||
var created = rig.Sink.CreatedVariables.Count(v => v == PressurePath);
|
||||
rig.Deploy(ThreeDriversRenamed, Rev('c')); // adds drv-3 only: a surgical PureAdd
|
||||
rig.Sink.CreatedVariables.Count(v => v == PressurePath).ShouldBeGreaterThan(created);
|
||||
rig.Sink.RebuildCount.ShouldBe(1, "the repair must not need a rebuild");
|
||||
AwaitAssert(() => drv2.SubscribeCount.ShouldBe(3), PresenceBudget, cancellationToken: Ct);
|
||||
}
|
||||
|
||||
private static (string, string, string, string, string, bool)[] ThreeDriversWith(string drv1Name) =>
|
||||
[
|
||||
("drv-1", drv1Name, "dev1", "speed", "Float", false), ("drv-2", "Modbus2", "dev2", "pressure", "Float", false),
|
||||
("drv-3", "Modbus3", "dev3", "flow", "Float", false),
|
||||
];
|
||||
|
||||
private static RevisionHash Rev(char c) => RevisionHash.Parse(new string(c, 64));
|
||||
|
||||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||||
|
||||
private sealed class Rig
|
||||
{
|
||||
private readonly RuntimeActorTestBase _kit;
|
||||
private readonly IDbContextFactory<OtOpcUaConfigDbContext> _db;
|
||||
private readonly IActorRef _host;
|
||||
private readonly TestProbe _coordinator;
|
||||
|
||||
public RecordingSubscribableDriverFactory Factory { get; } = new("Modbus");
|
||||
public SelectiveFaultSink Sink { get; } = new();
|
||||
|
||||
public Rig(RuntimeActorTestBase kit, IDbContextFactory<OtOpcUaConfigDbContext> db)
|
||||
{
|
||||
_kit = kit;
|
||||
_db = db;
|
||||
_coordinator = kit.CreateTestProbe();
|
||||
var publish = kit.Sys.ActorOf(OpcUaPublishActor.PropsForTests(
|
||||
sink: Sink, applier: new AddressSpaceApplier(Sink, NullLogger<AddressSpaceApplier>.Instance)));
|
||||
_host = kit.Sys.ActorOf(DriverHostActor.Props(
|
||||
_db, TestNode, _coordinator.Ref,
|
||||
driverFactory: Factory,
|
||||
localRoles: new HashSet<string> { "driver" },
|
||||
dependencyMux: kit.CreateTestProbe().Ref,
|
||||
opcUaPublishActor: publish,
|
||||
virtualTagEvaluator: NullVirtualTagEvaluator.Instance,
|
||||
virtualTagHostOverride: kit.CreateTestProbe().Ref));
|
||||
}
|
||||
|
||||
public RecordingSubscribableDriver Driver(string id)
|
||||
{
|
||||
RecordingSubscribableDriver? found = null;
|
||||
_kit.AwaitAssert(() => (found = Factory.Created.LastOrDefault(d => d.DriverInstanceId == id)).ShouldNotBeNull(),
|
||||
PresenceBudget, cancellationToken: Ct);
|
||||
return found!;
|
||||
}
|
||||
|
||||
/// <summary>Dispatches and waits for the ack — which the host releases only after the address-space outcome (and
|
||||
/// after any re-push that outcome triggers has been sent).</summary>
|
||||
public void Deploy((string, string, string, string, string, bool)[] tags, RevisionHash rev, bool expectDegraded = false)
|
||||
{
|
||||
var id = V3ArtifactSeeder.SeedV3Deployment(_db, rev, tags, NoRefs, enabled: true);
|
||||
_host.Tell(new DispatchDeployment(id, rev, CorrelationId.NewId()));
|
||||
var ack = _coordinator.FishForMessage<ApplyAck>(m => m.DeploymentId == id, PresenceBudget, cancellationToken: Ct);
|
||||
ack.Outcome.ShouldBe(ApplyAckOutcome.Applied);
|
||||
ack.Degraded.ShouldBe(expectDegraded, ack.DegradedReason);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A sink that refuses to create ONE variable (by NodeId) while <see cref="FailVariable"/> names it.</summary>
|
||||
private sealed class SelectiveFaultSink : IOpcUaAddressSpaceSink
|
||||
{
|
||||
private readonly object _gate = new();
|
||||
private readonly List<string> _created = new();
|
||||
public volatile string? FailVariable;
|
||||
public int RebuildCount;
|
||||
|
||||
public IReadOnlyList<string> CreatedVariables
|
||||
{
|
||||
get { lock (_gate) return _created.ToArray(); }
|
||||
}
|
||||
|
||||
public void WriteValue(string nodeId, object? value, uint statusCode, DateTime sourceTimestampUtc, AddressSpaceRealm realm = AddressSpaceRealm.Uns) { }
|
||||
public void WriteAlarmQuality(string alarmNodeId, uint statusCode, DateTime sourceTimestampUtc, AddressSpaceRealm realm) { }
|
||||
public void WriteAlarmCondition(string alarmNodeId, AlarmConditionSnapshot state, DateTime occurredUtc, AddressSpaceRealm realm = AddressSpaceRealm.Uns) { }
|
||||
public void MaterialiseAlarmCondition(string alarmNodeId, string equipmentNodeId, string displayName, string alarmType, int severity, AddressSpaceRealm realm, bool isNative = false) { }
|
||||
public void EnsureFolder(string folderNodeId, string? parentNodeId, string displayName, AddressSpaceRealm realm = AddressSpaceRealm.Uns) { }
|
||||
|
||||
public void EnsureVariable(string variableNodeId, string? parentFolderNodeId, string displayName, string dataType, bool writable, AddressSpaceRealm realm, string? historianTagname = null, bool isArray = false, uint? arrayLength = null, bool refuseArrayOnScalar = false)
|
||||
{
|
||||
if (variableNodeId == FailVariable) throw new InvalidOperationException("simulated variable fault");
|
||||
lock (_gate) _created.Add(variableNodeId);
|
||||
}
|
||||
|
||||
public void RebuildAddressSpace() => Interlocked.Increment(ref RebuildCount);
|
||||
public void RaiseNodesAddedModelChange(string affectedNodeId, AddressSpaceRealm realm = AddressSpaceRealm.Uns) { }
|
||||
public void WireAlarmNotifiers(string alarmNodeId, AddressSpaceRealm alarmRealm, IReadOnlyList<string> notifierFolderNodeIds, AddressSpaceRealm notifierFolderRealm) { }
|
||||
public void AddReference(string sourceNodeId, AddressSpaceRealm sourceRealm, string targetNodeId, AddressSpaceRealm targetRealm, string referenceType = "Organizes") { }
|
||||
}
|
||||
}
|
||||
+75
@@ -198,6 +198,81 @@ public sealed class OpcUaPublishActorApplyOutcomeTests : RuntimeActorTestBase
|
||||
Deploy(actor, BuildArtifact(new[] { "eq-1", "eq-2" }, "Second", withAlarm: true)).Degraded.ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #995 R-11 x #977 R-4 review: the empty-plan repair of a degraded composition may CREATE nodes (valueless) whose
|
||||
/// drivers the deploy skipped, so it must report <c>AddressSpaceRebuilt</c> (the driver host's re-push signal) —
|
||||
/// and a genuinely clean no-op afterwards must not (positive control: the signal is not stuck on).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void The_empty_plan_repair_of_a_degraded_rebuild_asks_for_a_re_push_and_the_clean_no_op_after_it_does_not()
|
||||
{
|
||||
var sink = new FaultingSink(throwOnEnsureFolder: false);
|
||||
var applier = new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance);
|
||||
var actor = Sys.ActorOf(OpcUaPublishActor.PropsForTests(sink: sink, applier: applier));
|
||||
|
||||
var first = Deploy(actor, BuildArtifact(new[] { "eq-1" }, "First", withAlarm: true));
|
||||
first.Degraded.ShouldBeFalse();
|
||||
first.AddressSpaceRebuilt.ShouldBeFalse("control: a clean non-rebuild apply does not ask for a re-push");
|
||||
|
||||
sink.ThrowOnAlarmCondition = true;
|
||||
var changed = BuildArtifact(new[] { "eq-1" }, "Second", withAlarm: true);
|
||||
Deploy(actor, changed).Degraded.ShouldBeTrue();
|
||||
sink.RebuildCount.ShouldBe(1);
|
||||
|
||||
sink.ThrowOnAlarmCondition = false;
|
||||
var repair = Deploy(actor, changed); // same composition ⇒ empty plan ⇒ the repair branch
|
||||
repair.Degraded.ShouldBeFalse();
|
||||
repair.AddressSpaceRebuilt.ShouldBeTrue("the repair created what the degraded rebuild could not place");
|
||||
sink.RebuildCount.ShouldBe(1);
|
||||
|
||||
var noOp = Deploy(actor, changed);
|
||||
noOp.Degraded.ShouldBeFalse();
|
||||
noOp.AddressSpaceRebuilt.ShouldBeFalse("a clean no-op after the repair created nothing");
|
||||
}
|
||||
|
||||
/// <summary>The #977 R-4 whole-composition re-ensure (an unrelated surgical deploy after a degraded rebuild) likewise.</summary>
|
||||
[Fact]
|
||||
public void The_R4_whole_composition_repair_asks_for_a_re_push_and_a_clean_add_after_it_does_not()
|
||||
{
|
||||
var sink = new FaultingSink(throwOnEnsureFolder: false);
|
||||
var applier = new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance);
|
||||
var actor = Sys.ActorOf(OpcUaPublishActor.PropsForTests(sink: sink, applier: applier));
|
||||
|
||||
Deploy(actor, BuildArtifact(new[] { "eq-1" }, "First", withAlarm: true)).Degraded.ShouldBeFalse();
|
||||
sink.ThrowOnAlarmCondition = true;
|
||||
Deploy(actor, BuildArtifact(new[] { "eq-1" }, "Second", withAlarm: true)).Degraded.ShouldBeTrue();
|
||||
|
||||
sink.ThrowOnAlarmCondition = false;
|
||||
var repair = Deploy(actor, BuildArtifact(new[] { "eq-1", "eq-2" }, "Second", withAlarm: true));
|
||||
repair.Degraded.ShouldBeFalse();
|
||||
repair.AddressSpaceRebuilt.ShouldBeTrue("the R-4 re-ensure created what the degraded rebuild could not place");
|
||||
sink.RebuildCount.ShouldBe(1);
|
||||
|
||||
var clean = Deploy(actor, BuildArtifact(new[] { "eq-1", "eq-2", "eq-3" }, "Second", withAlarm: true));
|
||||
clean.Degraded.ShouldBeFalse();
|
||||
clean.AddressSpaceRebuilt.ShouldBeFalse("an ordinary surgical add after the repair is not a repair");
|
||||
}
|
||||
|
||||
/// <summary>A degraded NON-rebuild (composition held back) — the next apply's re-diff creates the missing node.</summary>
|
||||
[Fact]
|
||||
public void The_apply_after_a_degraded_non_rebuild_asks_for_a_re_push()
|
||||
{
|
||||
var sink = new FaultingSink(throwOnEnsureFolder: false);
|
||||
var applier = new AddressSpaceApplier(sink, NullLogger<AddressSpaceApplier>.Instance);
|
||||
var actor = Sys.ActorOf(OpcUaPublishActor.PropsForTests(sink: sink, applier: applier));
|
||||
|
||||
Deploy(actor, BuildArtifact(new[] { "eq-1" }, "eq-1", withAlarm: false)).Degraded.ShouldBeFalse();
|
||||
sink.ThrowOnEnsureFolder = true;
|
||||
Deploy(actor, BuildArtifact(new[] { "eq-1", "eq-2" }, "eq-1", withAlarm: false)).Degraded.ShouldBeTrue();
|
||||
sink.RebuildCount.ShouldBe(0);
|
||||
|
||||
sink.ThrowOnEnsureFolder = false;
|
||||
var next = Deploy(actor, BuildArtifact(new[] { "eq-1", "eq-2" }, "eq-1", withAlarm: false));
|
||||
next.Degraded.ShouldBeFalse();
|
||||
next.AddressSpaceRebuilt.ShouldBeTrue();
|
||||
sink.RebuildCount.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_first_apply_after_a_supervision_restart_rebuilds_instead_of_diffing_against_an_empty_baseline()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user