Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -469,27 +469,29 @@ type AsyncModule() =
member _.``error on one workflow should cancel all others``() =
task {
use failOnlyOne = new Semaphore(0, 1)
// Start from 1.
let mutable running = new CountdownEvent(1)
let mutable cancelled = 0
let mutable started = 0

let job i = async {
use! holder = Async.OnCancel (running.Signal >> ignore)
running.AddCount 1
do! failOnlyOne |> Async.AwaitWaitHandle |> Async.Ignore
running.Signal() |> ignore
failwith "boom"
let! ct = Async.CancellationToken
Interlocked.Increment &started |> ignore
try
do! failOnlyOne |> Async.AwaitWaitHandle |> Async.Ignore
failwith "boom"
finally
if ct.IsCancellationRequested then
Interlocked.Increment &cancelled |> ignore

}

let test = Async.Parallel [ for i in 1 .. 100 -> job i ] |> Async.Catch |> Async.Ignore |> Async.StartAsTask
// Wait for more than one job to start
while running.CurrentCount < 2 do
while started < 2 do
do! Task.Yield()
printfn $"started jobs: {running.CurrentCount - 1}"
printfn $"started jobs: {started}"
failOnlyOne.Release() |> ignore
do! test
// running.CurrentCount should eventually settle back at 1. Signal it one more time and it should be 0.
running.Signal() |> ignore
return! Async.AwaitWaitHandle running.WaitHandle
Assert.Equal(cancelled, started - 1)
}

[<Fact>]
Expand Down
Loading