test(site-runtime): starvation test asserts a timed-out eval resolves as unknown, not false (SRT-2, WP3 task 3.7)
This commit is contained in:
+23
-14
@@ -136,9 +136,12 @@ public class TriggerEvalStarvationTests : TestKit, IDisposable
|
||||
/// <summary>
|
||||
/// GROUP 2 — the evaluation deadline is measured from ENQUEUE, so time spent waiting on a
|
||||
/// saturated <see cref="TriggerEvalGate"/> burns the same budget. With the gate fully
|
||||
/// occupied for the whole assertion window, a queued evaluation must still resolve (as
|
||||
/// false) at its timeout rather than stalling indefinitely — and the trigger must drain
|
||||
/// rather than park, so the next change still evaluates.
|
||||
/// occupied for the whole assertion window, a queued evaluation must still resolve at its
|
||||
/// timeout rather than stalling indefinitely — and the trigger must drain rather than park,
|
||||
/// so the next change still evaluates. Since the 2026-12-02 review (SRT-2) a timed-out
|
||||
/// evaluation is "unknown": it resolves WITHOUT changing the alarm's state (it used to be
|
||||
/// coerced to false and clear the alarm), and reports a rate-limited site event — that event
|
||||
/// is the proof it resolved at its deadline.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
@@ -147,6 +150,8 @@ public class TriggerEvalStarvationTests : TestKit, IDisposable
|
||||
using var scheduler = new ScriptExecutionScheduler(1);
|
||||
using var evalGate = new TriggerEvalGate(1);
|
||||
var options = new SiteRuntimeOptions { TriggerEvalTimeoutSeconds = 1 };
|
||||
var siteLog = new TestSupport.FakeSiteEventLogger();
|
||||
IServiceProvider services = new TestSupport.SingleServiceProvider(siteLog);
|
||||
|
||||
var instanceProbe = CreateTestProbe();
|
||||
var alarm = ActorOf(Props.Create(() => new AlarmActor(
|
||||
@@ -155,11 +160,11 @@ public class TriggerEvalStarvationTests : TestKit, IDisposable
|
||||
{
|
||||
CanonicalName = "ExprAlarm",
|
||||
TriggerType = "Expression",
|
||||
TriggerConfiguration = "{\"expression\":\"true\"}",
|
||||
TriggerConfiguration = "{\"expression\":\"Attributes[\\\"A\\\"]?.ToString() != \\\"0\\\"\"}",
|
||||
PriorityLevel = 500
|
||||
},
|
||||
null, _sharedLibrary, options, NullLogger<AlarmActor>.Instance,
|
||||
CompileTriggerExpression("true"), null, null, null, null, scheduler, evalGate)));
|
||||
CompileTriggerExpression("Attributes[\"A\"]?.ToString() != \"0\""), null, null, services, null, scheduler, evalGate)));
|
||||
|
||||
// 1. Free gate: the expression evaluates true and the alarm raises.
|
||||
alarm.Tell(new AttributeValueChanged("Inst1", "A", "A", 1, "Good", DateTimeOffset.UtcNow));
|
||||
@@ -171,23 +176,27 @@ public class TriggerEvalStarvationTests : TestKit, IDisposable
|
||||
Assert.Equal(0, evalGate.AvailablePermits);
|
||||
|
||||
// 3. The next evaluation can never acquire the gate. Its deadline was armed at
|
||||
// enqueue, so it cancels at ~1 s, is treated as false, and clears the alarm.
|
||||
// Previously the clock started at dequeue, so this would hang forever.
|
||||
// enqueue, so it cancels at ~1 s and resolves as UNKNOWN: the alarm stays Active and a
|
||||
// site event reports the failed evaluation. Previously the clock started at dequeue,
|
||||
// so this would hang forever (and before SRT-2 it cleared the alarm).
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
alarm.Tell(new AttributeValueChanged("Inst1", "A", "A", 2, "Good", DateTimeOffset.UtcNow));
|
||||
var cleared = instanceProbe.ExpectMsg<AlarmStateChanged>(TimeSpan.FromSeconds(10));
|
||||
alarm.Tell(new AttributeValueChanged("Inst1", "A", "A", 0, "Good", DateTimeOffset.UtcNow));
|
||||
AwaitAssert(() => Assert.Contains(siteLog.OfType("alarm"), e =>
|
||||
e.Message.Contains("could not be evaluated", StringComparison.Ordinal)),
|
||||
TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(50));
|
||||
stopwatch.Stop();
|
||||
|
||||
Assert.Equal(AlarmState.Normal, cleared.State);
|
||||
Assert.True(stopwatch.Elapsed < TimeSpan.FromSeconds(6),
|
||||
$"queued evaluation took {stopwatch.Elapsed} to resolve — the deadline is not enqueue-anchored");
|
||||
Assert.Equal(0, evalGate.AvailablePermits); // still held: it genuinely never ran
|
||||
instanceProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(200)); // no state change from an unknown result
|
||||
|
||||
// 4. Not parked: releasing the gate and sending another change evaluates again.
|
||||
// 4. Not parked: releasing the gate and sending another change evaluates again — the
|
||||
// genuine false now clears the alarm.
|
||||
evalGate.Release();
|
||||
alarm.Tell(new AttributeValueChanged("Inst1", "A", "A", 3, "Good", DateTimeOffset.UtcNow));
|
||||
var reRaised = instanceProbe.ExpectMsg<AlarmStateChanged>(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal(AlarmState.Active, reRaised.State);
|
||||
alarm.Tell(new AttributeValueChanged("Inst1", "A", "A", 0, "Good", DateTimeOffset.UtcNow));
|
||||
var cleared = instanceProbe.ExpectMsg<AlarmStateChanged>(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal(AlarmState.Normal, cleared.State);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user