Skip to content
Merged
251 changes: 132 additions & 119 deletions ParallelKit.Harness.ps1

Large diffs are not rendered by default.

181 changes: 87 additions & 94 deletions ParallelKit.ps1

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Testing/cmdlet-hang/inner.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# One stress trial, run in a fresh powershell.exe by run.ps1.
# Runs -Rounds separate Invoke-PkRunspaceJobs calls (a new runspace pool, so
# Runs -Rounds separate Invoke-PkRunspaceBatch calls (a new runspace pool, so
# fresh runspaces, each round). In each round all -Workers workers wait on a
# gate, then are released at the same instant into the -Mode body - the
# "first cmdlet call in two fresh runspaces at once" case this was written to
Expand Down Expand Up @@ -120,7 +120,7 @@ try {
}
}.GetNewClosure()
$crashes = [System.Collections.Generic.List[string]]::new()
$out = Invoke-PkRunspaceJobs -MaxParallel $Workers -JobParams $jobs -WorkerScript $worker `
$out = Invoke-PkRunspaceBatch -MaxConcurrent $Workers -JobParams $jobs -WorkerScript $worker `
-PollCallback $poll -JobCrashedHandler { param($err) $crashes.Add([string]$err) }.GetNewClosure()
if ($state.GateTimedOut) { Write-Progress2 "round $round gate-timeout" }
foreach ($c in $crashes) { Write-Progress2 "round $round crash: $c" }
Expand Down
2 changes: 1 addition & 1 deletion Testing/hosts/check-host.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ try {
Write-Log ("batch returned after " + [int]$sw.Elapsed.TotalSeconds + "s: aborted=" + $batch.Aborted + " results=" + $batch.Results.Count + " exit codes=" + (@($batch.Results | ForEach-Object { $_.ExitCode }) -join ','))

Reset-PkAbortState
$jobs = Invoke-PkRunspaceJobs -MaxParallel 2 -JobParams @(@{ Id = 1 }, @{ Id = 2 }) -WorkerScript { param($Id) Write-PkMessage ("worker " + $Id); $Id * 10 } -ResultHandler { param($r) Write-Log ("worker result: " + $r) }
$jobs = Invoke-PkRunspaceBatch -MaxConcurrent 2 -JobParams @(@{ Id = 1 }, @{ Id = 2 }) -WorkerScript { param($Id) Write-PkMessage ("worker " + $Id); $Id * 10 } -ResultHandler { param($r) Write-Log ("worker result: " + $r) }
Write-Log ("runspace jobs: crashed=" + $jobs.CrashedCount + " aborted=" + $jobs.Aborted)
Write-Log "done"
} catch {
Expand Down
8 changes: 4 additions & 4 deletions Testing/readme-examples/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ $tests.Add(@{ Name = 'Worker that returns its own error object'; Body = $pngs +
. $Kit
$global:results = [System.Collections.Generic.List[object]]::new()
$jobsParams = @{
MaxParallel = 2
MaxConcurrent = 2
JobParams = @(@{ Path = (Join-Path $Data 'a.png') }, @{ Path = (Join-Path $Data 'missing.png') })
ResultHandler = { param($r) $global:results.Add($r) }

'@ + (Get-Example 'Error = $_.Exception.Message') + @'

}
$out = Invoke-PkRunspaceJobs @jobsParams
$out = Invoke-PkRunspaceBatch @jobsParams
Test-Check ($global:results.Count -eq 2) "a result per job ($($global:results.Count) of 2)"
$good = @($global:results | Where-Object { $_.Path -like '*a.png' })[0]
$missing = @($global:results | Where-Object { $_.Path -like '*missing.png' })[0]
Expand All @@ -166,7 +166,7 @@ function Write-MyLog($Message, $Level) { $global:log.Add("$Level|$Message") }

'@ + (Get-Example 'Set-PkMessageHandler { param($Message, $Level)') + @'

$null = Invoke-PkRunspaceJobs -MaxParallel 2 -JobParams @(@{ N = 1 }) -WorkerScript { param($N) Write-PkMessage "from worker $N" -Level Warning }
$null = Invoke-PkRunspaceBatch -MaxConcurrent 2 -JobParams @(@{ N = 1 }) -WorkerScript { param($N) Write-PkMessage "from worker $N" -Level Warning }
Write-PkMessage 'from the main thread' -Level Error
Test-Check ($global:log -contains 'Warn|from worker 1') "a worker's -Level Warning arrives as Warn ($($global:log -join '; '))"
Test-Check ($global:log -contains 'Error|from the main thread') 'a main-thread message arrives'
Expand Down Expand Up @@ -240,7 +240,7 @@ $tests.Add(@{ Name = "Get-FileHash and a worker's `$ErrorActionPreference"; Body
. $Kit
$missingFile = Join-Path $Data 'missing.png'
$global:results = [System.Collections.Generic.List[string]]::new()
$null = Invoke-PkRunspaceJobs -MaxParallel 1 -JobParams @(@{ Path = $missingFile; UseParam = $false }, @{ Path = $missingFile; UseParam = $true }) -ResultHandler { param($r) $global:results.Add($r) } -WorkerScript {
$null = Invoke-PkRunspaceBatch -MaxConcurrent 1 -JobParams @(@{ Path = $missingFile; UseParam = $false }, @{ Path = $missingFile; UseParam = $true }) -ResultHandler { param($r) $global:results.Add($r) } -WorkerScript {
param($Path, $UseParam)
$ErrorActionPreference = 'Stop'
try {
Expand Down
4 changes: 2 additions & 2 deletions Testing/soak/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Each round runs 250 programs through Invoke-PkProcessBatch: quick ones,
# ones that print more than a -MaxOutputChars cap, ones that leave a helper
# holding their output past -StreamTimeoutMs, and ones killed at a time
# limit. Then 100 runspace jobs through Invoke-PkRunspaceJobs. Helpers left
# limit. Then 100 runspace jobs through Invoke-PkRunspaceBatch. Helpers left
# holding output carry -w 4328 on their command line, and only those are
# killed between rounds.
#
Expand Down Expand Up @@ -74,7 +74,7 @@ try {
$timedOut = @($b.Results | Where-Object { $_.TimedOut }).Count
if (-not $Compat) { $capped = @($b.Results | Where-Object { $_.StdoutDroppedChars -gt 0 }).Count }
}
if (-not $NoRunspace) { $rsErrors = (Invoke-PkRunspaceJobs -MaxParallel 8 -JobParams $jobParams -WorkerScript { param($Id) $Id * 2 }).Errors.Count }
if (-not $NoRunspace) { $rsErrors = (Invoke-PkRunspaceBatch -MaxConcurrent 8 -JobParams $jobParams -WorkerScript { param($Id) $Id * 2 }).Errors.Count }
Stop-SoakHelpers
$c = Get-SoakCounts
$row = [pscustomobject]@{ Round = $r; Seconds = [math]::Round($sw.Elapsed.TotalSeconds, 1); Handles = $c.Handles; Threads = $c.Threads; ManagedMB = $c.ManagedMB; PrivateMB = $c.PrivateMB; Bad = $bad; TimedOut = $timedOut; Capped = $capped; RunspaceErrors = $rsErrors }
Expand Down
Loading