From bf78e3e7bf2a9b62b74e3f931841a3d97083cdfb Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 5 Jun 2026 09:59:41 -0400 Subject: [PATCH] test(e2e): harden CliRunner timeout drain + skip-counter (review fixes) --- .../Cluster/CliRunner.cs | 5 ++++- .../Cluster/ClusterAvailability.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/CliRunner.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/CliRunner.cs index 1c40b2e9..16d3b72d 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/CliRunner.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/CliRunner.cs @@ -41,7 +41,7 @@ public static class CliRunner private const string CliPassword = "password"; private static readonly object DllLock = new(); - private static string? _cliDll; + private static volatile string? _cliDll; /// /// Management URL the CLI connects to (via the Traefik load balancer). @@ -111,6 +111,9 @@ public static class CliRunner catch (OperationCanceledException) { TryKill(process); + // Drain both pipes so the abandoned read tasks complete cleanly before disposal. + try { await Task.WhenAll(stdoutTask, stderrTask).WaitAsync(TimeSpan.FromSeconds(5)); } + catch { /* best-effort — we are already throwing TimeoutException */ } throw new TimeoutException( $"CLI [{string.Join(' ', args)}] did not exit within {Timeout.TotalSeconds:F0}s and was killed."); } diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/ClusterAvailability.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/ClusterAvailability.cs index 1ebedd81..acf02473 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/ClusterAvailability.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Cluster/ClusterAvailability.cs @@ -32,7 +32,7 @@ public static class ClusterAvailability { if (!cached) { - SkippedCount++; + System.Threading.Interlocked.Increment(ref SkippedCount); } return cached; @@ -46,7 +46,7 @@ public static class ClusterAvailability catch { _cached = false; - SkippedCount++; + System.Threading.Interlocked.Increment(ref SkippedCount); } return _cached.Value;