test(scripted-alarms): cover bootstrap-restore path forwarding alarms (T10 review)

This commit is contained in:
Joseph Doherty
2026-06-10 15:24:39 -04:00
parent fc0d43a3dc
commit a8640a9331
@@ -157,6 +157,48 @@ public sealed class DriverHostActorTests : RuntimeActorTestBase
plan.PredicateSource.ShouldContain("ctx.GetTag");
}
/// <summary>Bootstrap-restore: a node that already has an <c>Applied</c> NodeDeploymentState
/// row for a ScriptedAlarm-carrying deployment re-forwards the
/// <see cref="ScriptedAlarmHostActor.ApplyScriptedAlarms"/> on PreStart (no dispatch needed), so a
/// restarted node restores its live ScriptedAlarm children.</summary>
[Fact]
public void Restore_on_bootstrap_forwards_EquipmentScriptedAlarms_to_scripted_alarm_host()
{
var db = NewInMemoryDbFactory();
var deploymentId = SeedDeploymentWithScriptedAlarm(db, RevA);
// Seed an Applied NodeDeploymentState row so Bootstrap() detects the Applied branch and
// calls RestoreApplied — no DispatchDeployment needed.
using (var ctx = db.CreateDbContext())
{
ctx.NodeDeploymentStates.Add(new Configuration.Entities.NodeDeploymentState
{
NodeId = TestNode.Value,
DeploymentId = deploymentId.Value,
Status = NodeDeploymentStatus.Applied,
StartedAtUtc = DateTime.UtcNow,
AppliedAtUtc = DateTime.UtcNow,
});
ctx.SaveChanges();
}
var coordinator = CreateTestProbe();
var alarmHost = CreateTestProbe();
// No DispatchDeployment — Bootstrap() should detect the Applied row and run RestoreApplied,
// which routes through PushDesiredSubscriptions and forwards ApplyScriptedAlarms.
Sys.ActorOf(DriverHostActor.Props(
db, TestNode, coordinator.Ref,
localRoles: new HashSet<string> { "driver" },
scriptedAlarmHostOverride: alarmHost.Ref));
var apply = alarmHost.ExpectMsg<ScriptedAlarmHostActor.ApplyScriptedAlarms>(TimeSpan.FromSeconds(5));
var plan = apply.Plans.ShouldHaveSingleItem();
plan.ScriptedAlarmId.ShouldBe("al-1");
plan.EquipmentId.ShouldBe("eq-1");
plan.Name.ShouldBe("Overheat");
plan.PredicateSource.ShouldContain("ctx.GetTag");
}
private static DeploymentId SeedDeploymentWithScriptedAlarm(
IDbContextFactory<OtOpcUaConfigDbContext> db, RevisionHash rev)
{