Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4559cfd

Browse files
matthiddsyme
authored andcommitted
add another test for #3254 (#3367)
* add another test for #3254, ported from paket. related to #3350 andfsprojects/Paket#2553* Fix exception message
1 parentf6049d5 commit4559cfd

File tree

1 file changed

+54
-1
lines changed
  • src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control

1 file changed

+54
-1
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/Cancellation.fs‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,60 @@ type CancellationType() =
229229
yieldasync{do linkedCts.Dispose()}
230230
}
231231
asyncs|> Async.Parallel|> Async.RunSynchronously|> ignore
232-
232+
233+
[<Test>]
234+
memberthis.AwaitTaskCancellationAfterAsyncTokenCancellation()=
235+
letStartCatchCancellation cancellationToken(work)=
236+
Async.FromContinuations(fun(cont,econt,_)->
237+
// When the child is cancelled, report OperationCancelled
238+
// as an ordinary exception to "error continuation" rather
239+
// than using "cancellation continuation"
240+
letccont e= econt e
241+
// Start the workflow using a provided cancellation token
242+
Async.StartWithContinuations( work, cont, econt, ccont,
243+
?cancellationToken=cancellationToken))
244+
245+
/// Like StartAsTask but gives the computation time to so some regular cancellation work
246+
letStartAsTaskProperCancel taskCreationOptions cancellationToken(computation:Async<_>):System.Threading.Tasks.Task<_>=
247+
lettoken= defaultArg cancellationToken Async.DefaultCancellationToken
248+
lettaskCreationOptions= defaultArg taskCreationOptions System.Threading.Tasks.TaskCreationOptions.None
249+
lettcs=new System.Threading.Tasks.TaskCompletionSource<_>("StartAsTaskProperCancel", taskCreationOptions)
250+
251+
leta=
252+
async{
253+
try
254+
// To ensure we don't cancel this very async (which is required to properly forward the error condition)
255+
let!result= StartCatchCancellation(Some token) computation
256+
do
257+
tcs.SetResult(result)
258+
with exn->
259+
tcs.SetException(exn)
260+
}
261+
Async.Start(a)
262+
tcs.Task
263+
264+
letcts=new CancellationTokenSource()
265+
lettcs= System.Threading.Tasks.TaskCompletionSource<_>()
266+
lett=
267+
async{
268+
do! tcs.Task|> Async.AwaitTask
269+
}
270+
|> StartAsTaskProperCancel None(Some cts.Token)
271+
272+
// First cancel the token, then set the task as cancelled.
273+
async{
274+
do! Async.Sleep100
275+
cts.Cancel()
276+
do! Async.Sleep100
277+
tcs.TrySetException(TimeoutException"Task timed out after token.")
278+
|> ignore
279+
}|> Async.Start
280+
281+
try
282+
letres= t.Wait(1000)
283+
Assert.Fail(sprintf"Excepted TimeoutException wrapped in an AggregateException, but got%A" res)
284+
with:? AggregateExceptionas agg->()
285+
233286
[<Test>]
234287
memberthis.Equality()=
235288
letcts1=new CancellationTokenSource()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp