test(mtconnect): a stale-session pump may finish before the restart retires it

Since the T-1 generation guard a pump stops on its own once its session generation
is gone, so the STAB-20 test's 'the retired pump is retained' assertion raced it
(intermittent failure). The test now accepts either outcome - retained for shutdown
to join, or already finished - which is what the retention exists to guarantee.

Refs #743

Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
Joseph Doherty
2026-10-22 15:45:54 -04:00
parent 994c0b3b19
commit 29c829b540
@@ -70,6 +70,7 @@ public sealed class MTConnectPumpGenerationTests
// A second subscriber arrives mid-restart: it starts a pump on the (still-live) old client.
await driver.SubscribeAsync(["dev1_pos"], TimeSpan.FromMilliseconds(50), Ct);
var staleSessionPump = driver.SampleStreamTask.ShouldNotBeNull();
await clientA.WaitForSampleCallsAsync(2).WaitAsync(Watchdog, Ct);
restart.IsCompleted.ShouldBeFalse();
@@ -77,9 +78,12 @@ public sealed class MTConnectPumpGenerationTests
await restart.WaitAsync(Watchdog, Ct);
// The pump retired by the restart is retained so shutdown can join it (it used to be dropped
// un-awaited and could write health after the new session was Healthy).
// un-awaited and could write health after the new session was Healthy). Since review 2026-10-21 T-1 a
// pump also stops by itself once it sees its session generation is gone, so it may already have
// finished before the restart got to retire it — either way it is not left running unjoined.
retired = driver.SupersededPumpTasks;
retired.ShouldNotBeEmpty();
(retired.Contains(staleSessionPump) || staleSessionPump.IsCompleted).ShouldBeTrue(
"the stale-session pump must be retained for shutdown to join, or already be gone");
// The restart installed a new client; the standing subscription must be streaming from IT.
await clientB.WaitForSampleCallsAsync(1).WaitAsync(Watchdog, Ct);