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

Try fix parallelism tests #45

Merged
merged 4 commits into from
Apr 8, 2024
Merged
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
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<!-- owners is not supported in MSBuild -->
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking --test:ParallelIlxGen --test:ParallelOptimization </OtherFlags>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>$(NoWarn);FS2003; NU1903; NU1904</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!--
* FS3517 InlineIfLambda didn't get inlined
-->
Expand Down
53 changes: 34 additions & 19 deletions tests/IcedTasks.Tests/CancellablePoolingValueTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -956,32 +956,47 @@ module CancellablePoolingValueTaskTests =
}

]

testList "MergeSourcesParallel" [
testSequencedGroup "MergeSourcesParallel - cancellablePoolingValueTask"
<| testList "MergeSourcesParallel" [
testPropertyWithConfig Expecto.fsCheckConfig "parallelism"
<| fun () ->
asyncEx {
let! ct = Async.CancellationToken
let sequencedList = ResizeArray<_>()
let parallelList = ResizeArray<_>()

let doOtherStuff (l: ResizeArray<_>) x =
let fakeWork id yieldTimes (l: ResizeArray<_>) =
cancellablePoolingValueTask {
lock l (fun () -> l.Add(x))
do! Task.yieldMany 1000
lock l (fun () -> l.Add(id))
do! Task.yieldMany yieldTimes
let dt = DateTimeOffset.UtcNow
lock l (fun () -> l.Add(x))
lock l (fun () -> l.Add(id))
return dt
}

// Have earlier tasks take longer to complete
// so we can see if they are sequenced or not
let fakeWork1 l =
cancellablePoolingValueTask {
do! Task.Delay 15
let! x = fakeWork 1 10000 l
do! Task.Delay 15
return x
}

let fakeWork2 = fakeWork 2 750
let fakeWork3 = fakeWork 3 500
let fakeWork4 = fakeWork 4 250
let fakeWork5 = fakeWork 5 100
let fakeWork6 = fakeWork 6 1

let! sequenced =
cancellablePoolingValueTask {
let! a = doOtherStuff sequencedList 1
let! b = doOtherStuff sequencedList 2
let! c = doOtherStuff sequencedList 3
let! d = doOtherStuff sequencedList 4
let! e = doOtherStuff sequencedList 5
let! f = doOtherStuff sequencedList 6
let! a = fakeWork1 sequencedList
let! b = fakeWork2 sequencedList
let! c = fakeWork3 sequencedList
let! d = fakeWork4 sequencedList
let! e = fakeWork5 sequencedList
let! f = fakeWork6 sequencedList

return [
a
Expand All @@ -995,12 +1010,12 @@ module CancellablePoolingValueTaskTests =

let! paralleled =
cancellablePoolingValueTask {
let! a = doOtherStuff parallelList 1
and! b = doOtherStuff parallelList 2
and! c = doOtherStuff parallelList 3
and! d = doOtherStuff parallelList 4
and! e = doOtherStuff parallelList 5
and! f = doOtherStuff parallelList 6
let! a = fakeWork1 parallelList
and! b = fakeWork2 parallelList
and! c = fakeWork3 parallelList
and! d = fakeWork4 parallelList
and! e = fakeWork5 parallelList
and! f = fakeWork6 parallelList

return [
a
Expand Down
52 changes: 34 additions & 18 deletions tests/IcedTasks.Tests/CancellableTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -915,32 +915,48 @@ module CancellableTaskTests =
}

]

testList "MergeSourcesParallel" [
testSequencedGroup "MergeSourcesParallel - cancellableTask"
<| testList "MergeSourcesParallel" [
testPropertyWithConfig Expecto.fsCheckConfig "parallelism"
<| fun () ->
asyncEx {
let! ct = Async.CancellationToken
let sequencedList = ResizeArray<_>()
let parallelList = ResizeArray<_>()

let doOtherStuff (l: ResizeArray<_>) x =
let fakeWork id yieldTimes (l: ResizeArray<_>) =
cancellableTask {
lock l (fun () -> l.Add(x))
do! Task.yieldMany 1000
lock l (fun () -> l.Add(id))
do! Task.yieldMany yieldTimes
let dt = DateTimeOffset.UtcNow
lock l (fun () -> l.Add(x))
lock l (fun () -> l.Add(id))
return dt
}

// Have earlier tasks take longer to complete
// so we can see if they are sequenced or not
let fakeWork1 l =
cancellableTask {
do! Task.Delay 15
let! x = fakeWork 1 10000 l
do! Task.Delay 15
return x
}

let fakeWork2 = fakeWork 2 750
let fakeWork3 = fakeWork 3 500
let fakeWork4 = fakeWork 4 250
let fakeWork5 = fakeWork 5 100
let fakeWork6 = fakeWork 6 1

let! sequenced =
cancellableTask {
let! a = doOtherStuff sequencedList 1
let! b = doOtherStuff sequencedList 2
let! c = doOtherStuff sequencedList 3
let! d = doOtherStuff sequencedList 4
let! e = doOtherStuff sequencedList 5
let! f = doOtherStuff sequencedList 6
let! a = fakeWork1 sequencedList
let! b = fakeWork2 sequencedList
let! c = fakeWork3 sequencedList
let! d = fakeWork4 sequencedList
let! e = fakeWork5 sequencedList
let! f = fakeWork6 sequencedList

return [
a
Expand All @@ -954,12 +970,12 @@ module CancellableTaskTests =

let! paralleled =
cancellableTask {
let! a = doOtherStuff parallelList 1
and! b = doOtherStuff parallelList 2
and! c = doOtherStuff parallelList 3
and! d = doOtherStuff parallelList 4
and! e = doOtherStuff parallelList 5
and! f = doOtherStuff parallelList 6
let! a = fakeWork1 parallelList
and! b = fakeWork2 parallelList
and! c = fakeWork3 parallelList
and! d = fakeWork4 parallelList
and! e = fakeWork5 parallelList
and! f = fakeWork6 parallelList

return [
a
Expand Down
52 changes: 34 additions & 18 deletions tests/IcedTasks.Tests/CancellableValueTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -953,31 +953,47 @@ module CancellableValueTaskTests =
Expect.equal actual 6 ""
}
]

testList "MergeSourcesParallel" [
testSequencedGroup "MergeSourcesParallel - cancellableValueTask"
<| testList "MergeSourcesParallel" [
testPropertyWithConfig Expecto.fsCheckConfig "parallelism"
<| fun () ->
asyncEx {
let sequencedList = ResizeArray<_>()
let parallelList = ResizeArray<_>()

let doOtherStuff (l: ResizeArray<_>) x =
let fakeWork id yieldTimes (l: ResizeArray<_>) =
cancellableValueTask {
lock l (fun () -> l.Add(x))
do! Task.yieldMany 1000
lock l (fun () -> l.Add(id))
do! Task.yieldMany yieldTimes
let dt = DateTimeOffset.UtcNow
lock l (fun () -> l.Add(x))
lock l (fun () -> l.Add(id))
return dt
}

// Have earlier tasks take longer to complete
// so we can see if they are sequenced or not
let fakeWork1 l =
cancellableValueTask {
do! Task.Delay 15
let! x = fakeWork 1 10000 l
do! Task.Delay 15
return x
}

let fakeWork2 = fakeWork 2 750
let fakeWork3 = fakeWork 3 500
let fakeWork4 = fakeWork 4 250
let fakeWork5 = fakeWork 5 100
let fakeWork6 = fakeWork 6 1

let! sequenced =
cancellableValueTask {
let! a = doOtherStuff sequencedList 1
let! b = doOtherStuff sequencedList 2
let! c = doOtherStuff sequencedList 3
let! d = doOtherStuff sequencedList 4
let! e = doOtherStuff sequencedList 5
let! f = doOtherStuff sequencedList 6
let! a = fakeWork1 sequencedList
let! b = fakeWork2 sequencedList
let! c = fakeWork3 sequencedList
let! d = fakeWork4 sequencedList
let! e = fakeWork5 sequencedList
let! f = fakeWork6 sequencedList

return [
a
Expand All @@ -991,12 +1007,12 @@ module CancellableValueTaskTests =

let! paralleled =
cancellableValueTask {
let! a = doOtherStuff parallelList 1
and! b = doOtherStuff parallelList 2
and! c = doOtherStuff parallelList 3
and! d = doOtherStuff parallelList 4
and! e = doOtherStuff parallelList 5
and! f = doOtherStuff parallelList 6
let! a = fakeWork1 parallelList
and! b = fakeWork2 parallelList
and! c = fakeWork3 parallelList
and! d = fakeWork4 parallelList
and! e = fakeWork5 parallelList
and! f = fakeWork6 parallelList

return [
a
Expand Down
52 changes: 34 additions & 18 deletions tests/IcedTasks.Tests/PoolingValueTaskTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -679,32 +679,48 @@ module PoolingValueTaskTests =
}

]

testList "MergeSourcesParallel" [
testSequencedGroup "MergeSourcesParallel - poolingValueTask"
<| testList "MergeSourcesParallel" [
testPropertyWithConfig Expecto.fsCheckConfig "parallelism"
<| fun () ->
asyncEx {
let! ct = Async.CancellationToken
let sequencedList = ResizeArray<_>()
let parallelList = ResizeArray<_>()

let doOtherStuff (l: ResizeArray<_>) x =
let fakeWork id yieldTimes (l: ResizeArray<_>) =
poolingValueTask {
lock l (fun () -> l.Add(x))
do! Task.yieldMany 1000
lock l (fun () -> l.Add(id))
do! Task.yieldMany yieldTimes
let dt = DateTimeOffset.UtcNow
lock l (fun () -> l.Add(x))
lock l (fun () -> l.Add(id))
return dt
}

// Have earlier tasks take longer to complete
// so we can see if they are sequenced or not
let fakeWork1 l =
poolingValueTask {
do! Task.Delay 15
let! x = fakeWork 1 10000 l
do! Task.Delay 15
return x
}

let fakeWork2 = fakeWork 2 750
let fakeWork3 = fakeWork 3 500
let fakeWork4 = fakeWork 4 250
let fakeWork5 = fakeWork 5 100
let fakeWork6 = fakeWork 6 1

let! sequenced =
poolingValueTask {
let! a = doOtherStuff sequencedList 1
let! b = doOtherStuff sequencedList 2
let! c = doOtherStuff sequencedList 3
let! d = doOtherStuff sequencedList 4
let! e = doOtherStuff sequencedList 5
let! f = doOtherStuff sequencedList 6
let! a = fakeWork1 sequencedList
let! b = fakeWork2 sequencedList
let! c = fakeWork3 sequencedList
let! d = fakeWork4 sequencedList
let! e = fakeWork5 sequencedList
let! f = fakeWork6 sequencedList

return [
a
Expand All @@ -718,12 +734,12 @@ module PoolingValueTaskTests =

let! paralleled =
poolingValueTask {
let! a = doOtherStuff parallelList 1
and! b = doOtherStuff parallelList 2
and! c = doOtherStuff parallelList 3
and! d = doOtherStuff parallelList 4
and! e = doOtherStuff parallelList 5
and! f = doOtherStuff parallelList 6
let! a = fakeWork1 parallelList
and! b = fakeWork2 parallelList
and! c = fakeWork3 parallelList
and! d = fakeWork4 parallelList
and! e = fakeWork5 parallelList
and! f = fakeWork6 parallelList

return [
a
Expand Down
Loading
Loading