Skip to content

Commit

Permalink
Add test that AwaitTask ignore async cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frassle committed Aug 29, 2019
1 parent c322b87 commit 75500f1
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type AsyncType() =
let a = async {
cts.CancelAfter (100)
doSpinloop()
}
}
#if !NET46
let t : Task<unit> =
#else
Expand All @@ -174,6 +174,31 @@ type AsyncType() =
| _ -> reraise()
Assert.IsTrue (t.IsCompleted, "Task is not completed")

[<Test>]
member this.``AwaitTask ignores Async cancellation`` () =
let cts = new CancellationTokenSource()
let tcs = new TaskCompletionSource<unit>()
let innerTcs = new TaskCompletionSource<unit>()
let a = innerTcs.Task |> Async.AwaitTask

Async.StartWithContinuations(a, tcs.SetResult, tcs.SetException, ignore >> tcs.SetCanceled, cts.Token)

cts.CancelAfter(100)
try
let result = tcs.Task.Wait(300)
Assert.IsFalse (result)
with :? AggregateException -> Assert.Fail "Should not finish, yet"

innerTcs.SetResult ()

try
this.WaitASec tcs.Task
with :? AggregateException as a ->
match a.InnerException with
| :? TaskCanceledException -> ()
| _ -> reraise()
Assert.IsTrue (tcs.Task.IsCompleted, "Task is not completed")

[<Test>]
member this.StartTask () =
let s = "Hello tasks!"
Expand Down

0 comments on commit 75500f1

Please sign in to comment.