From 68461fbfb6ec8ffb2fc240f8a40ef5e791575de5 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 17 Aug 2026 05:39:52 -0400 Subject: [PATCH] test(historian): justify/tighten the shutdown watch window; single read of RemoveCallCount per poll --- .../ContinuousHistorizationRecorderTests.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Historian/ContinuousHistorizationRecorderTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Historian/ContinuousHistorizationRecorderTests.cs index cc3ac255..2a8c7bde 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Historian/ContinuousHistorizationRecorderTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Historian/ContinuousHistorizationRecorderTests.cs @@ -609,12 +609,22 @@ public sealed class ContinuousHistorizationRecorderTests : TestKit // the queued count moving off 2. Either fires the moment the unfixed recorder books the failure and // truncates, so a regression fails in milliseconds rather than after a fixed sleep; only the passing // case pays the full window. + // + // 1s is the window, and it is already generous headroom rather than a guess: everything it waits on + // is prompt on this fixture — the cancellation of the writer's `Task.Delay(Timeout.Infinite, ct)` is + // essentially synchronous (and `writer.Cancelled` above has already fired), the fold that would + // truncate runs immediately behind it, and the recorder's own cadence here is a 20ms drain interval + // with a 20-50ms backoff. The unfixed recorder trips this in ~150ms including startup, so the + // remaining ~6x is CI-load slack, not mechanism. var watch = Stopwatch.StartNew(); - while (watch.Elapsed < TimeSpan.FromSeconds(2)) + while (watch.Elapsed < TimeSpan.FromSeconds(1)) { + // Read once per iteration: the condition and its failure message must report the SAME + // observation, or a red run names a count that is not the one that tripped. + int removeCalls = outbox.RemoveCallCount; Assert.True( - outbox.RemoveCallCount == 0, - $"the cancelled pass acked: RemoveAsync ran {outbox.RemoveCallCount}x, truncating the queue"); + removeCalls == 0, + $"the cancelled pass acked: RemoveAsync ran {removeCalls}x, truncating the queue"); int queued = await outbox.CountAsync(default); Assert.True(queued == 2, $"the cancelled pass changed the queue depth: expected 2, saw {queued}"); await Task.Delay(25);