Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Oct 9, 2024
1 parent b29460f commit e1afbd6
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,22 @@ type AsyncModule() =

[<Fact>]
member _.``error on one workflow should cancel all others``() =
let go = new ManualResetEvent(false)
let mutable counter = 0
let job i = async {
if i = 55 then
go.Set() |> ignore
failwith "boom"
else
do! Async.AwaitWaitHandle go |> Async.Ignore
counter <- counter + 1
}
task {
use failOnlyOne = new Semaphore(0, 1)
let mutable cancelled = 0

let t = Async.Parallel [ for i in 1 .. 100 -> job i ] |> Async.Catch |> Async.Ignore |> Async.StartAsTask
t.Wait()
let job i = async {
use! holder = Async.OnCancel (fun () -> Interlocked.Increment &cancelled |> ignore)
do! failOnlyOne |> Async.AwaitWaitHandle |> Async.Ignore
failwith "boom"
}

Assert.AreEqual(0, counter)
let test = Async.Parallel [ for i in 1 .. 100 -> job i ] |> Async.Catch |> Async.Ignore |> Async.StartAsTask
do! Task.Delay 100
failOnlyOne.Release() |> ignore
do! test
Assert.Equal(99, cancelled)
}

[<Fact>]
member _.``AwaitWaitHandle.ExceptionsAfterTimeout``() =
Expand Down

0 comments on commit e1afbd6

Please sign in to comment.