From 29c829b5408dd4bd17b301cb8da54692389cafc7 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 22 Oct 2026 15:45:54 -0400 Subject: [PATCH] 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 --- .../MTConnectPumpGenerationTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/MTConnectPumpGenerationTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/MTConnectPumpGenerationTests.cs index 710c8f1d..476b8d53 100644 --- a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/MTConnectPumpGenerationTests.cs +++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/MTConnectPumpGenerationTests.cs @@ -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);