Skip to content

Commit 3de5a5a

Browse files
T-GroCopilot
andauthored
Fix flaky CancellationPropagatesToTask test (#19569)
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> Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
1 parent d11ff7e commit 3de5a5a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/AsyncType.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,13 @@ type AsyncType() =
255255

256256
[<Fact>]
257257
member _.CancellationPropagatesToTask () =
258+
let ewh = new ManualResetEvent(false)
258259
let a = async {
260+
ewh.Set() |> Assert.True
259261
while true do ()
260262
}
261263
let t = Async.StartAsTask a
264+
ewh.WaitOne() |> Assert.True
262265
Async.CancelDefaultToken ()
263266
let mutable exceptionThrown = false
264267
try

0 commit comments

Comments
 (0)