Skip to content

Commit 4854792

Browse files
committed
failing test for blocking calls
1 parent 6613af0 commit 4854792

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,48 @@ let ``AsyncSeq.bufferByTime`` () =
470470

471471
Assert.True ((actual = expected))
472472

473+
[<Test>]
474+
let ``AsyncSeq.bufferByCountAndTime should not block`` () =
475+
let op =
476+
asyncSeq {
477+
while true do
478+
do! Async.Sleep 1000
479+
yield 0
480+
}
481+
|> AsyncSeq.bufferByCountAndTime 10 1000
482+
|> AsyncSeq.take 3
483+
|> AsyncSeq.iter (ignore)
484+
485+
// should return immediately
486+
// while a blocking call would take > 3sec
487+
let watch = System.Diagnostics.Stopwatch.StartNew()
488+
let cts = new CancellationTokenSource()
489+
Async.StartWithContinuations(op, ignore, ignore, ignore, cts.Token)
490+
watch.Stop()
491+
cts.Cancel(false)
492+
Assert.Less (watch.ElapsedMilliseconds, 1000L)
493+
494+
[<Test>]
495+
let ``AsyncSeq.bufferByTime should not block`` () =
496+
let op =
497+
asyncSeq {
498+
while true do
499+
do! Async.Sleep 1000
500+
yield 0
501+
}
502+
|> AsyncSeq.bufferByTime 1000
503+
|> AsyncSeq.take 3
504+
|> AsyncSeq.iter (ignore)
505+
506+
// should return immediately
507+
// while a blocking call would take > 3sec
508+
let watch = System.Diagnostics.Stopwatch.StartNew()
509+
let cts = new CancellationTokenSource()
510+
Async.StartWithContinuations(op, ignore, ignore, ignore, cts.Token)
511+
watch.Stop()
512+
cts.Cancel(false)
513+
Assert.Less (watch.ElapsedMilliseconds, 1000L)
514+
473515
[<Test>]
474516
let ``try finally works no exception``() =
475517
let x = ref 0

0 commit comments

Comments
 (0)