Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore AwaitTaskCancellationAfterAsyncTokenCancellation test to original shape #17923

Merged
merged 1 commit into from
Oct 25, 2024
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 @@ -265,26 +265,27 @@ type CancellationType() =

let cts = new CancellationTokenSource()
let tcs = System.Threading.Tasks.TaskCompletionSource<_>()
let test() =
let t =
async {
do! tcs.Task |> Async.AwaitTask
}
|> StartAsTaskProperCancel None (Some cts.Token) :> Task
|> StartAsTaskProperCancel None (Some cts.Token)

// First cancel the token, then set the task as cancelled.
async {
do! Async.Sleep 100
cts.Cancel()
do! Async.Sleep 100
tcs.TrySetException (TimeoutException "Task timed out after token.")
|> ignore
|> ignore
} |> Async.Start

task {
let! agg = Assert.ThrowsAsync<AggregateException>(test)
let inner = agg.InnerException
Assert.True(inner :? TimeoutException, $"Excepted TimeoutException wrapped in an AggregateException, but got %A{inner}")
}
try
let res = t.Wait(2000)
let msg = sprintf "Excepted TimeoutException wrapped in an AggregateException, but got %A" res
printfn "failure msg: %s" msg
Assert.Fail (msg)
with :? AggregateException as agg -> ()

// Simpler regression test for https://github.com/dotnet/fsharp/issues/3254
[<Fact>]
Expand Down
Loading