Skip to content

Commit

Permalink
Test TaskSeq extensions (#49)
Browse files Browse the repository at this point in the history
* Test TaskSeq extensions

* MSBuild.StructuredLogger 2.2.243

* no longer need macos14, latest covers it

* macos being weird pt1
  • Loading branch information
TheAngryByrd authored Jun 8, 2024
1 parent 9301abe commit 485b666
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# Builds for Debug and Release configurations
configuration: [Debug, Release]
# Builds for Ubuntu, Windows, and macOS
os: [ubuntu-latest, windows-latest, macOS-latest, macos-14]
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ group Test
nuget TimeProviderExtensions
nuget YoloDev.Expecto.TestSdk >= 0.14.2
nuget Microsoft.NET.Test.Sdk >= 17.7.2
nuget FSharp.Control.TaskSeq
nuget FSharp.Control.TaskSeq 0.4.0

// [ FAKE GROUP ]
group Build
Expand All @@ -41,5 +41,5 @@ group Build
nuget Fake.BuildServer.GitHubActions ~> 6
nuget Argu
nuget Octokit >= 0.50
nuget MSBuild.StructuredLogger 2.1.858
nuget MSBuild.StructuredLogger 2.2.243

6 changes: 3 additions & 3 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ NUGET
System.Security.Principal.Windows (>= 5.0) - restriction: || (&& (>= monoandroid) (< netstandard1.3)) (&& (< monoandroid) (>= netcoreapp2.0)) (>= monotouch) (&& (< net46) (< netcoreapp2.0) (>= netstandard2.0)) (>= net461) (>= netcoreapp2.1) (>= uap10.1) (>= xamarinios) (>= xamarinmac) (>= xamarintvos) (>= xamarinwatchos)
Microsoft.Win32.SystemEvents (7.0) - restriction: >= net6.0
Mono.Posix.NETStandard (1.0) - restriction: >= netstandard2.0
MSBuild.StructuredLogger (2.1.858)
MSBuild.StructuredLogger (2.2.243)
Microsoft.Build.Framework (>= 17.5) - restriction: >= netstandard2.0
Microsoft.Build.Utilities.Core (>= 17.5) - restriction: >= netstandard2.0
Newtonsoft.Json (13.0.3) - restriction: >= netstandard2.0
Expand Down Expand Up @@ -369,8 +369,8 @@ NUGET
FsCheck (>= 2.16.5 < 3.0) - restriction: >= net6.0
FsCheck (2.16.6) - restriction: >= net6.0
FSharp.Core (>= 4.2.3) - restriction: || (>= net452) (>= netstandard1.6)
FSharp.Control.TaskSeq (0.3)
FSharp.Core (>= 6.0.2) - restriction: >= netstandard2.1
FSharp.Control.TaskSeq (0.4)
FSharp.Core (>= 6.0.1) - restriction: >= netstandard2.1
FSharp.Core (7.0.401) - restriction: >= netstandard2.1
Microsoft.Bcl.AsyncInterfaces (8.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (>= net462) (&& (>= netstandard2.0) (< netstandard2.1))
Expand Down
1 change: 1 addition & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);FS0044</NoWarn> <!-- Suppress warning FS0044: TaskSeq deprecated something that's in the BCL and gives a dumb error -->
</PropertyGroup>
</Project>
47 changes: 44 additions & 3 deletions tests/IcedTasks.Tests/AsyncExTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ module AsyncExTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

let! actual =
asyncEx {
Expand Down Expand Up @@ -719,7 +719,7 @@ module AsyncExTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand Down Expand Up @@ -754,7 +754,7 @@ module AsyncExTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand All @@ -776,6 +776,47 @@ module AsyncExTests =
}
}


#if TEST_NETSTANDARD2_1 || TEST_NET6_0_OR_GREATER
testCaseAsync "TaskSeq receives CancellationToken"
<| async {

do!
asyncEx {

let loops = 1

let mutable CancellationToken = CancellationToken.None

let asyncSeq =
taskSeq {
for i in 0..loops do
do!
asyncEx {
let! ct = Async.CancellationToken
CancellationToken <- ct
}

yield ()
}

use cts = new CancellationTokenSource()

let actual =
asyncEx {
for i in asyncSeq do
do! Task.Yield()
}

do!
Async.StartAsTask(actual, cancellationToken = cts.Token)
|> Async.AwaitTask

Expect.equal CancellationToken cts.Token ""
}
}
#endif

]
]

Expand Down
42 changes: 39 additions & 3 deletions tests/IcedTasks.Tests/CancellablePoolingValueTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace IcedTasks.Tests

open System
open Expecto
open FSharp.Control
open System.Threading
open System.Threading.Tasks
open IcedTasks
Expand Down Expand Up @@ -801,7 +802,7 @@ module CancellablePoolingValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(fun _ -> valueTask { do! Task.Yield() })

let! actual =
cancellablePoolingValueTask {
Expand Down Expand Up @@ -832,7 +833,7 @@ module CancellablePoolingValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(fun _ -> valueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand Down Expand Up @@ -865,7 +866,7 @@ module CancellablePoolingValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(fun _ -> valueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand All @@ -884,6 +885,41 @@ module CancellablePoolingValueTaskTests =
""
}
}
testCaseAsync "TaskSeq receives CancellationToken"
<| async {

do!
cancellablePoolingValueTask {

let loops = 1

let mutable CancellationToken = CancellationToken.None

let asyncSeq =
taskSeq {
for i in 0..loops do
do!
cancellablePoolingValueTask {
let! ct = CancellableTask.getCancellationToken ()
CancellationToken <- ct
}

yield ()
}

use cts = new CancellationTokenSource()

let actual =
cancellablePoolingValueTask {
for i in asyncSeq do
do! Task.Yield()
}

do! actual cts.Token

Expect.equal CancellationToken cts.Token ""
}
}
]


Expand Down
45 changes: 41 additions & 4 deletions tests/IcedTasks.Tests/CancellableTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ namespace IcedTasks.Tests

open System
open Expecto
open IcedTasks
open FSharp.Control
open System.Threading
open System.Threading.Tasks
open IcedTasks

module CancellableTaskTests =
open System.Collections.Concurrent
Expand Down Expand Up @@ -763,7 +764,7 @@ module CancellableTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

let! actual =
cancellableTask {
Expand Down Expand Up @@ -793,7 +794,7 @@ module CancellableTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand Down Expand Up @@ -827,7 +828,7 @@ module CancellableTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand All @@ -845,8 +846,44 @@ module CancellableTaskTests =
cts.Token
""
}
}
#if TEST_NETSTANDARD2_1 || TEST_NET6_0_OR_GREATER
testCaseAsync "TaskSeq receives CancellationToken"
<| async {

do!
cancellableTask {

let loops = 1

let mutable CancellationToken = CancellationToken.None

let asyncSeq =
taskSeq {
for i in 0..loops do
do!
cancellableTask {
let! ct = CancellableTask.getCancellationToken ()
CancellationToken <- ct
}

yield ()
}

use cts = new CancellationTokenSource()

let actual =
cancellableTask {
for i in asyncSeq do
do! Task.Yield()
}

do! actual cts.Token

Expect.equal CancellationToken cts.Token ""
}
}
#endif
]
testList "MergeSources" [

Expand Down
47 changes: 44 additions & 3 deletions tests/IcedTasks.Tests/CancellableValueTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System.Threading
open System.Threading.Tasks
open IcedTasks
open System.Collections.Generic
open FSharp.Control

module CancellableValueTaskTests =
open TimeProviderExtensions
Expand Down Expand Up @@ -801,7 +802,7 @@ module CancellableValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

let! actual =
cancellableValueTask {
Expand Down Expand Up @@ -831,7 +832,7 @@ module CancellableValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand Down Expand Up @@ -864,7 +865,7 @@ module CancellableValueTaskTests =
AsyncEnumerable.forXtoY
0
loops
(fun _ -> valueTaskUnit { do! Task.Yield() })
(cancellableValueTask { do! Task.Yield() })

use cts = new CancellationTokenSource()

Expand All @@ -884,6 +885,46 @@ module CancellableValueTaskTests =
}
}

#if TEST_NETSTANDARD2_1 || TEST_NET6_0_OR_GREATER
testCaseAsync "TaskSeq receives CancellationToken"
<| async {

do!
cancellableValueTask {

let loops = 1

let mutable CancellationToken = CancellationToken.None

let asyncSeq =
taskSeq {
for i in 0..loops do
do!
cancellableValueTask {
let! ct =
CancellableValueTask.getCancellationToken ()

CancellationToken <- ct
}

yield ()
}

use cts = new CancellationTokenSource()

let actual =
cancellableValueTask {
for i in asyncSeq do
do! Task.Yield()
}

do! actual cts.Token

Expect.equal CancellationToken cts.Token ""
}
}
#endif

]

testList "MergeSources" [
Expand Down
Loading

0 comments on commit 485b666

Please sign in to comment.