Skip to content
Open
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Unreleased

* Test coverage: Added tests for previously-untested public API functions `AsyncSeq.tryFirst`, `AsyncSeq.firstOrDefault`, `AsyncSeq.zipWithParallel`, `AsyncSeq.combineLatestWithAsync`, and `AsyncSeq.toObservable`. No functional changes.
* Test coverage: Added tests for `AsyncSeq.bufferByCount` (obsolete alias of `chunkBySize`) and `Seq.ofAsyncSeq`, which previously had no dedicated test coverage. No functional changes.
* Fixed Fable CI build: `Microsoft.Bcl.AsyncInterfaces` was pinned to a specific version (`10.0.7`) that was older than the version resolved transitively via `System.Threading.Channels`, causing a `NU1605` package downgrade error that made Fable's project cracker fail during `dotnet fable`. The reference now uses `Version="*"` (matching `System.Threading.Channels`) so both resolve consistently. (#334)
* Tests: Added comprehensive tests for `AsyncSeq.zapp`, `AsyncSeq.zappAsync`, and `AsyncSeq.compareWithAsync`, which previously had no dedicated test coverage.

Expand Down
46 changes: 46 additions & 0 deletions tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#endif
module AsyncSeqTests

#nowarn "44" // suppress Obsolete warnings for intentional tests of obsolete API (e.g. AsyncSeq.bufferByCount)

open NUnit.Framework
open FSharp.Control
open System
Expand Down Expand Up @@ -2094,7 +2096,7 @@
let actual =
ls
|> AsyncSeq.ofSeq
|> AsyncSeq.groupBy p

Check warning on line 2099 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupBy must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (snd >> AsyncSeq.toListAsync)
Assert.AreEqual(expected, actual)

Expand All @@ -2103,7 +2105,7 @@
let expected = asyncSeq { raise (exn("test")) }
let actual =
asyncSeq { raise (exn("test")) }
|> AsyncSeq.groupBy (fun i -> i % 3)

Check warning on line 2108 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupBy must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (snd >> AsyncSeq.toListAsync)
Assert.AreEqual(expected, actual)

Expand Down Expand Up @@ -4851,7 +4853,7 @@
let ``AsyncSeq.groupByAsync groups elements by async projection`` () =
let result =
AsyncSeq.ofSeq [1..6]
|> AsyncSeq.groupByAsync (fun x -> async { return x % 2 })

Check warning on line 4856 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupByAsync must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (fun (key, grp) -> async {
let! items = AsyncSeq.toArrayAsync grp
return key, Array.sort items })
Expand All @@ -4864,7 +4866,7 @@
let ``AsyncSeq.groupByAsync on empty sequence returns empty`` () =
let result =
AsyncSeq.empty<int>
|> AsyncSeq.groupByAsync (fun x -> async { return x % 2 })

Check warning on line 4869 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupByAsync must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.toArrayAsync
|> Async.RunSynchronously
Assert.AreEqual([||], result)
Expand All @@ -4873,7 +4875,7 @@
let ``AsyncSeq.groupByAsync with all-same key produces single group`` () =
let result =
AsyncSeq.ofSeq [1; 2; 3]
|> AsyncSeq.groupByAsync (fun _ -> async { return "same" })

Check warning on line 4878 in tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

View workflow job for this annotation

GitHub Actions / build

The result of groupByAsync must be consumed with a parallel combinator such as AsyncSeq.mapAsyncParallel. Sequential consumption will deadlock because sub-sequence completion depends on other sub-sequences being consumed concurrently.
|> AsyncSeq.mapAsyncParallel (fun (key, grp) -> async {
let! items = AsyncSeq.toArrayAsync grp
return key, Array.sort items })
Expand Down Expand Up @@ -5179,6 +5181,50 @@
Assert.IsTrue(completedEvent.Wait(2000))
Assert.AreEqual([||], received.ToArray())

// ===== bufferByCount (obsolete alias for chunkBySize) =====

#if !FABLE_COMPILER
[<Test>]
let ``AsyncSeq.bufferByCount chunks elements into buffers of specified size`` () =
let result =
AsyncSeq.ofSeq [1;2;3;4;5]
|> AsyncSeq.bufferByCount 2
|> AsyncSeq.toListSynchronously
Assert.AreEqual([ [|1;2|]; [|3;4|]; [|5|] ], result)

[<Test>]
let ``AsyncSeq.bufferByCount on empty sequence returns empty`` () =
let result =
AsyncSeq.empty<int>
|> AsyncSeq.bufferByCount 3
|> AsyncSeq.toListSynchronously
Assert.AreEqual([], result)

[<Test>]
let ``AsyncSeq.bufferByCount matches chunkBySize behavior`` () =
let xs = AsyncSeq.ofSeq [1..7]
let viaBufferByCount = xs |> AsyncSeq.bufferByCount 3 |> AsyncSeq.toListSynchronously
let viaChunkBySize = xs |> AsyncSeq.chunkBySize 3 |> AsyncSeq.toListSynchronously
Assert.AreEqual(viaChunkBySize, viaBufferByCount)
#pragma warning restore 0044

// ===== Seq.ofAsyncSeq =====

[<Test>]
let ``Seq.ofAsyncSeq converts async sequence to blocking sequence`` () =
let result = AsyncSeq.ofSeq [1;2;3;4] |> Seq.ofAsyncSeq |> Seq.toList
Assert.AreEqual([1;2;3;4], result)

[<Test>]
let ``Seq.ofAsyncSeq on empty async sequence returns empty seq`` () =
let result = AsyncSeq.empty<int> |> Seq.ofAsyncSeq |> Seq.toList
Assert.AreEqual([], result)

[<Test>]
let ``Seq.ofAsyncSeq consumes elements lazily`` () =
let result = AsyncSeq.ofSeq [1;2;3] |> Seq.ofAsyncSeq |> Seq.take 2 |> Seq.toList
Assert.AreEqual([1;2], result)
#endif
// ===== zapp / zappAsync =====

[<Test>]
Expand Down
Loading