Skip to content

add test and fix #3254 #3255

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

Merged
merged 6 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
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 @@ -162,7 +162,22 @@ type AsyncType() =
this.WaitASec t
Assert.IsTrue (t.IsCompleted)
Assert.AreEqual(s, t.Result)


[<Test>]
member this.RunSynchronouslyCancellationWithDelayedResult () =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some kind of timeout to this test? Assuming the fix is not in place that test would run forever. Perhaps configurable via nunit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought about that, but to be honest there are a lot of tests with similar expectations. Not sure a timeout there is worth it, but I can of course add one if you don't agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as it doesn't obscure the intention of the test I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done

let cts = new CancellationTokenSource()
let tcs = TaskCompletionSource<int>()
let _ = cts.Token.Register(fun () -> tcs.SetResult 42)
let a = async {
cts.CancelAfter (100)
let! result = tcs.Task |> Async.AwaitTask
return result }

try
Async.RunSynchronously(a, cancellationToken = cts.Token)
|> ignore
with :? OperationCanceledException as o -> ()

[<Test>]
member this.ExceptionPropagatesToTask () =
let a = async {
Expand Down
12 changes: 2 additions & 10 deletions src/fsharp/FSharp.Core/control.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,14 +1536,6 @@ namespace Microsoft.FSharp.Control
// Contains helpers that will attach continuation to the given task.
// Should be invoked as a part of protectedPrimitive(withResync) call
module TaskHelpers =
let private continueWithExtra token =
#if FSCORE_PORTABLE_OLD || FSCORE_PORTABLE_NEW
token |> ignore
TaskContinuationOptions.None
#else
token
#endif

let continueWith (task : Task<'T>, args, useCcontForTaskCancellation) =

let continuation (completedTask : Task<_>) : unit =
Expand All @@ -1557,7 +1549,7 @@ namespace Microsoft.FSharp.Control
else
args.cont completedTask.Result)) |> unfake

task.ContinueWith(Action<Task<'T>>(continuation), continueWithExtra args.aux.token) |> ignore |> fake
task.ContinueWith(Action<Task<'T>>(continuation)) |> ignore |> fake

let continueWithUnit (task : Task, args, useCcontForTaskCancellation) =

Expand All @@ -1572,7 +1564,7 @@ namespace Microsoft.FSharp.Control
else
args.cont ())) |> unfake

task.ContinueWith(Action<Task>(continuation), continueWithExtra args.aux.token) |> ignore |> fake
task.ContinueWith(Action<Task>(continuation)) |> ignore |> fake
#endif

#if FX_NO_REGISTERED_WAIT_HANDLES
Expand Down