From 03f301e30266f8e504f4be73a6a1e3667629ad77 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 2 Oct 2026 07:28:01 -0700 Subject: [PATCH] fix(test): tolerate delayed Windows process exit observation --- .../BoundedProcessWaitTests.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/OpenClaw.Shared.Tests/BoundedProcessWaitTests.cs b/tests/OpenClaw.Shared.Tests/BoundedProcessWaitTests.cs index 116141bed..01cac4023 100644 --- a/tests/OpenClaw.Shared.Tests/BoundedProcessWaitTests.cs +++ b/tests/OpenClaw.Shared.Tests/BoundedProcessWaitTests.cs @@ -29,10 +29,10 @@ await Assert.ThrowsAsync( () => BoundedProcessWait.WaitAsync(process, TimeSpan.FromMilliseconds(200))); stopwatch.Stop(); - Assert.True(process.HasExited); Assert.True( stopwatch.Elapsed < TimeSpan.FromSeconds(3), $"Timeout cleanup took {stopwatch.ElapsedMilliseconds} ms."); + await AssertExitsEventuallyAsync(process); } [Fact] @@ -51,10 +51,10 @@ public async Task WaitAsync_CancellationKillsProcessWithoutUsingTimeoutBudget() await Assert.ThrowsAnyAsync(() => wait); stopwatch.Stop(); - Assert.True(process.HasExited); Assert.True( stopwatch.Elapsed < TimeSpan.FromSeconds(3), $"Cancellation cleanup took {stopwatch.ElapsedMilliseconds} ms."); + await AssertExitsEventuallyAsync(process); } [Fact] @@ -70,7 +70,7 @@ await Assert.ThrowsAnyAsync( BoundedProcessWait.DefaultTimeout, cancellation.Token)); - Assert.True(process.HasExited); + await AssertExitsEventuallyAsync(process); } [Fact] @@ -164,6 +164,13 @@ private static string FindTestHost() return hostPath; } + private static async Task AssertExitsEventuallyAsync(Process process) + { + // Cleanup is intentionally bounded, so Windows may report the killed + // process exit just after WaitAsync has returned to its caller. + await process.WaitForExitAsync().WaitAsync(TimeSpan.FromSeconds(5)); + } + private static async Task ReadChildPidAsync(string pidFile) { var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(5);