feat(runtime): ScriptedAlarmActor state machine (engine wiring tracked as F9)

This commit is contained in:
Joseph Doherty
2026-05-26 05:09:03 -04:00
parent 39729bfe21
commit 95ef533822
2 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using Akka.Actor;
using Akka.TestKit;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Runtime.ScriptedAlarms;
using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.ScriptedAlarms;
public sealed class ScriptedAlarmActorTests : RuntimeActorTestBase
{
[Fact]
public void Full_state_cycle_publishes_StateChanged_to_parent_at_each_transition()
{
var parent = CreateTestProbe();
// Wrap the alarm actor under our probe as parent so StateChanged lands on the probe.
var actor = parent.ChildActorOf(ScriptedAlarmActor.Props("alarm-1"));
actor.Tell(new ScriptedAlarmActor.ConditionMet("threshold"));
var t1 = parent.ExpectMsg<ScriptedAlarmActor.StateChanged>();
t1.State.ShouldBe(ScriptedAlarmActorState.Active);
actor.Tell(new ScriptedAlarmActor.AcknowledgeAlarm("joe"));
var t2 = parent.ExpectMsg<ScriptedAlarmActor.StateChanged>();
t2.State.ShouldBe(ScriptedAlarmActorState.Acknowledged);
actor.Tell(new ScriptedAlarmActor.ConditionCleared());
var t3 = parent.ExpectMsg<ScriptedAlarmActor.StateChanged>();
t3.State.ShouldBe(ScriptedAlarmActorState.Inactive);
}
[Fact]
public void Duplicate_ConditionMet_in_Active_is_ignored()
{
var parent = CreateTestProbe();
var actor = parent.ChildActorOf(ScriptedAlarmActor.Props("alarm-1"));
actor.Tell(new ScriptedAlarmActor.ConditionMet("first"));
parent.ExpectMsg<ScriptedAlarmActor.StateChanged>();
actor.Tell(new ScriptedAlarmActor.ConditionMet("second"));
parent.ExpectNoMsg(TimeSpan.FromMilliseconds(200));
}
}