test(scripted-alarms): host-level redeploy restates an acked active alarm (#935)
This commit is contained in:
+62
@@ -975,4 +975,66 @@ public sealed class ScriptedAlarmHostActorTests : RuntimeActorTestBase
|
|||||||
|
|
||||||
publish.ExpectNoMsg(TimeSpan.FromMilliseconds(500), TestContext.Current.CancellationToken);
|
publish.ExpectNoMsg(TimeSpan.FromMilliseconds(500), TestContext.Current.CancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
// #935 — a redeploy is a restatement. The production store (LocalDb) has no Active column, so the
|
||||||
|
// engine used to re-seed a still-active alarm Inactive on every ApplyScriptedAlarms and re-activate it:
|
||||||
|
// Acked reset, an Activated row on `alerts`, and a re-assert stamped with the deploy instant.
|
||||||
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// <summary>Mirrors <c>LocalDbAlarmConditionStateStore</c>: a loaded row is always Inactive.</summary>
|
||||||
|
private sealed class ActiveDroppingStore : IAlarmStateStore
|
||||||
|
{
|
||||||
|
private readonly InMemoryAlarmStateStore _inner = new();
|
||||||
|
|
||||||
|
public async Task<AlarmConditionState?> LoadAsync(string alarmId, CancellationToken ct)
|
||||||
|
=> await _inner.LoadAsync(alarmId, ct) is { } row
|
||||||
|
? row with { Active = AlarmActiveState.Inactive, LastActiveUtc = null, LastClearedUtc = null }
|
||||||
|
: null;
|
||||||
|
|
||||||
|
public Task<IReadOnlyList<AlarmConditionState>> LoadAllAsync(CancellationToken ct) => _inner.LoadAllAsync(ct);
|
||||||
|
public Task SaveAsync(AlarmConditionState state, CancellationToken ct) => _inner.SaveAsync(state, ct);
|
||||||
|
public Task RemoveAsync(string alarmId, CancellationToken ct) => _inner.RemoveAsync(alarmId, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>#935: an acknowledged active alarm, redeployed, is re-asserted still Active + Acknowledged with the
|
||||||
|
/// timestamp of its last real transition (the ack), and nothing reaches <c>alerts</c>.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void A_redeploy_restates_an_acked_active_alarm_without_reactivating_it()
|
||||||
|
{
|
||||||
|
var publish = CreateTestProbe();
|
||||||
|
var mux = CreateTestProbe();
|
||||||
|
var alerts = CreateTestProbe();
|
||||||
|
SubscribeToAlerts(alerts);
|
||||||
|
var ct = TestContext.Current.CancellationToken;
|
||||||
|
|
||||||
|
var (host, _) = Spawn(publish, mux, store: new ActiveDroppingStore());
|
||||||
|
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms(new[] { Plan() }));
|
||||||
|
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: ct);
|
||||||
|
|
||||||
|
host.Tell(new VirtualTagActor.DependencyValueChanged("M.T", 99, DateTime.UtcNow));
|
||||||
|
publish.FishForMessage<OpcUaPublishActor.AlarmStateUpdate>(
|
||||||
|
m => m.State.Active && !m.State.Acknowledged, Timeout, cancellationToken: ct);
|
||||||
|
alerts.FishForMessage<AlarmTransitionEvent>(e => e.TransitionKind == "Activated", Timeout, cancellationToken: ct);
|
||||||
|
|
||||||
|
host.Tell(new AlarmCommand(AlarmId: "alm-1", Operation: "Acknowledge", User: "alice", Comment: null, UnshelveAtUtc: null));
|
||||||
|
publish.FishForMessage<OpcUaPublishActor.AlarmStateUpdate>(m => m.State.Acknowledged, Timeout, cancellationToken: ct);
|
||||||
|
alerts.FishForMessage<AlarmTransitionEvent>(e => e.TransitionKind == "Acknowledged", Timeout, cancellationToken: ct);
|
||||||
|
|
||||||
|
// The deploy.
|
||||||
|
var deployAt = DateTime.UtcNow;
|
||||||
|
host.Tell(new ScriptedAlarmHostActor.ApplyScriptedAlarms(new[] { Plan() }));
|
||||||
|
mux.ExpectMsg<DependencyMuxActor.RegisterInterest>(Timeout, cancellationToken: ct);
|
||||||
|
|
||||||
|
var reasserted = publish.ExpectMsg<OpcUaPublishActor.AlarmStateUpdate>(Timeout, cancellationToken: ct);
|
||||||
|
reasserted.State.Active.ShouldBeTrue();
|
||||||
|
reasserted.State.Acknowledged.ShouldBeTrue("a deploy must not un-acknowledge an operator-acked alarm");
|
||||||
|
// The re-assert carries LastTransitionUtc — the ack instant, before the deploy (it used to be the load instant).
|
||||||
|
reasserted.TimestampUtc.ShouldBeLessThan(deployAt, "condition Time stays at its last real transition, not the deploy");
|
||||||
|
// Known-state semantics unchanged (A1): the reload's held established-flip lands AFTER the re-assert…
|
||||||
|
publish.ExpectMsg<OpcUaPublishActor.MarkConditionsKnown>(Timeout, cancellationToken: ct).Known.ShouldBeTrue();
|
||||||
|
// …and nothing else follows: no re-activation projection, no alerts row.
|
||||||
|
publish.ExpectNoMsg(TimeSpan.FromMilliseconds(500), ct);
|
||||||
|
alerts.ExpectNoMsg(TimeSpan.FromMilliseconds(500), ct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user