Implement ForEach-Object -Parallel runspace reuse (#12122)

* Implement foreach parallel runspace reuse

* Change runspace dispose

* Refactor runspace reset check

* Fix race condition.

* Fix CodFactor issues

* Implement -UseNewRunspace parameter switch, add tests

* Fix Codacy error
This commit is contained in:
Paul Higinbotham authored and GitHub committed 2020-03-23 14:00:43 -07:00
1 parent 7a8094fd31
commit cce214e884
3 files changed
+185 -29

No files matched your search

@@ -314,6 +314,23 @@ Describe 'ForEach-Object -Parallel -AsJob Basic Tests' -Tags 'CI' {
}
}
Describe 'ForEach-Object -Parallel runspace pool tests' -Tags 'CI' {
It "Verifies job allocated runspace count is limited to pool size" {
$job = 1..4 | ForEach-Object -Parallel { Start-Sleep 1 } -AsJob -ThrottleLimit 2 | Wait-Job
$job.AllocatedRunspaceCount | Should -BeExactly 2
$job | Remove-Job
}
It "Verifies job with -UseNewRunspace switch allocates one runspace per iteration" {
$job = 1..10 | ForEach-Object -Parallel { $_ } -AsJob -ThrottleLimit 2 -UseNewRunspace | Wait-Job
$job.AllocatedRunspaceCount | Should -BeExactly 10
$job | Remove-Job
}
}
Describe 'ForEach-Object -Parallel Functional Tests' -Tags 'Feature' {
It 'Verifies job queuing and throttle limit' {