From a4479d849fb3d7018bfb31c8861442eabebeb507 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 10 Apr 2026 12:03:15 +0200 Subject: [PATCH] Fix flaky CancellationPropagatesToTask test Add synchronization to ensure the async computation has actually started running on the thread pool before cancelling the default token. Without this, under heavy CI load the thread pool may not schedule the async within the 1-second wait window, causing the task to never transition to Canceled state before the timeout. This mirrors the pattern already used by the CancellationPropagatesToGroup test which uses a ManualResetEvent for the same purpose. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs index 3bf50a19fb..d1d09dcd8a 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs @@ -255,10 +255,13 @@ type AsyncType() = [] member _.CancellationPropagatesToTask () = + let ewh = new ManualResetEvent(false) let a = async { + ewh.Set() |> Assert.True while true do () } let t = Async.StartAsTask a + ewh.WaitOne() |> Assert.True Async.CancelDefaultToken () let mutable exceptionThrown = false try