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

add test and fix #3254 #3255

Merged
merged 6 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/fsharp/FSharp.Core/control.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ namespace Microsoft.FSharp.Control
else
args.cont completedTask.Result)) |> unfake

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

Choose a reason for hiding this comment

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

Is this an intrinsic part of this fix? Or is only https://github.com/Microsoft/visualfsharp/pull/3255/files#diff-34ee82347e9e0b47265fcecaa4850174R1567 needed? If the latter, please remove this change to keep the changes entirely separate,

task.ContinueWith(Action<Task<'T>>(continuation)) |> ignore |> fake

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

Expand All @@ -1572,7 +1572,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