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);