Skip to content
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
43 changes: 23 additions & 20 deletions ParallelKit.Harness.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,12 @@ function Protect-HarnessPingChild {

# ==============================================================================
if (Test-HarnessSection 'A' "setup") {
$init = Initialize-ParallelKit -MaxConcurrentProcesses 8
$init = Initialize-ParallelKit
Test-Assert ($init.AbortHandler -eq $true) "abort handler registers"
Test-Assert ($init.ChildProcessJob -eq $true) "child-process job object initializes"
# For PkHarnessJobProbe, in several sections. Here because A always runs, and
# the handle exists only once the Job Object has been set up.
$jobHandle = [PkChildProcessJob].GetField('_job', [System.Reflection.BindingFlags]'NonPublic,Static').GetValue($null)
Test-Assert ($init.ThreadPool -eq $true) "ThreadPool is still `$true, for scripts that check it"
$w = 0; $io = 0
[System.Threading.ThreadPool]::GetMinThreads([ref]$w, [ref]$io)
Test-Assert ($w -eq $poolMinBefore -and $io -eq $poolIoBefore) ("Initialize-ParallelKit leaves the thread pool's minimum alone (" + $w + "/" + $io + ", was " + $poolMinBefore + "/" + $poolIoBefore + ")")
Expand Down Expand Up @@ -400,7 +399,8 @@ try { $null = Start-PkProcess -FilePath 'C:\no\such\program.exe' } catch { $thre
Test-Assert $threw "a program that can't be started throws a clear error (not a silent null)"
$j = Start-PkProcess -FilePath $cmdExe -Arguments '/c exit 0'
$null = Wait-PkProcess -Process $j.Proc -TimeoutMs 5000
Test-Assert ([PkChildProcessJob]::Assign($j.Proc) -or $j.Proc.HasExited) "started processes are tied to the job object"
$assignWhy = $null
Test-Assert ([PkChildProcessJob]::Assign($j.Proc, [ref]$assignWhy) -or $j.Proc.HasExited) "started processes are tied to the job object"
$j.Proc.Dispose()

# ConvertTo-PkArgumentString: exact output for the tricky cases, then a
Expand Down Expand Up @@ -1470,7 +1470,7 @@ try { . '$kitPath'; Write-Output 'LOADED' } catch { Write-Output ('REFUSED: ' +
"@)
$stale = Invoke-PkProcessWithTimeout -FilePath $selfExe -Arguments ('-NoProfile -ExecutionPolicy Bypass -File "' + $staleScript + '"') -TimeoutMs 60000
[System.IO.File]::Delete($staleScript)
Test-Assert ($stale.Stdout -like '*REFUSED:*older version of the kit*start a new one*') "loading the kit over an older copy's types is refused with a clear message"
Test-Assert ($stale.Stdout -like '*REFUSED:*a different version of the kit*start a new one*') ("loading the kit over another version's types is refused with a clear message (" + ([string]$stale.Stdout).Trim() + ")")

# Invoke-PkRun keeps the PC from idle-sleeping only while it runs. Checked
# on this thread: SetThreadExecutionState returns the thread's previous
Expand Down Expand Up @@ -1586,7 +1586,7 @@ Test-Assert ((Get-HarnessShape $shapeJobs) -eq 'ForceStoppedCount,CrashedCount,A
$shapeFindings = Test-PkWorkerSafety -WorkerScript { param($Id) $null = [Func[int]]{ 1 } }
$shapeFinding = $shapeFindings[0]
Test-Assert ((Get-HarnessShape $shapeFinding) -eq 'Rule,Where,Line,Text') ("worker-safety findings are objects (" + (Get-HarnessShape $shapeFinding) + ")")
Test-Assert ((Get-HarnessShape (Initialize-ParallelKit)) -eq 'AbortHandler,ChildProcessJob,ThreadPool,Version,StartMode') "Initialize-ParallelKit returns an object"
Test-Assert ((Get-HarnessShape (Initialize-ParallelKit)) -eq 'AbortHandler,ChildProcessJob,Version,StartMode') "Initialize-ParallelKit returns an object"

$fields = @('Command', 'ExitCode', 'Stdout', 'Stderr', 'StreamTimedOut', 'StreamError', 'StartError', 'Aborted', 'TimedOut', 'Duration')
$batch = Invoke-PkProcessBatch -MaxConcurrent 1 -Commands @(
Expand Down Expand Up @@ -3104,8 +3104,8 @@ if (Test-HarnessSection 'AF' "parameter handling: advanced functions, aliases, t
$simpleFunctions = @($publicFunctions | Where-Object { -not (Get-Command $_).CmdletBinding })
Test-Assert ($simpleFunctions.Count -eq 0) ("every public function rejects unknown arguments (not: " + ($simpleFunctions -join ', ') + ")")
$threw = $null
try { $null = Initialize-ParallelKit -AbortTimeoutSeconds 4 } catch { $threw = [string]$_ }
Test-Assert ($threw -like '*AbortTimeoutSeconds*') "Initialize-ParallelKit -AbortTimeoutSeconds (an engine's parameter) is an error, not ignored"
try { $null = Initialize-ParallelKit -MaxConcurrent 4 } catch { $threw = [string]$_ }
Test-Assert ($threw -like '*MaxConcurrent*') "Initialize-ParallelKit -MaxConcurrent (an engine's parameter) is an error, not ignored"
$threw = $null
try { $null = Test-PkAbortSignal 'extra' } catch { $threw = [string]$_ }
Test-Assert ($null -ne $threw) "Test-PkAbortSignal refuses an argument it doesn't take"
Expand Down Expand Up @@ -3675,21 +3675,24 @@ $null = Invoke-PkRunspaceBatch -MaxConcurrent 1 -JobParams (New-JobList -Jobs @(
$apiLevels = (@($script:messages | Where-Object { $_.Message -eq 'pk-level-worker' } | ForEach-Object { $_.Level }) -join ',')
Test-Assert ($apiLevels -ceq 'Warn') ("and the same from a worker (" + $apiLevels + ")")

# The dispatcher's -PollCallback, and its alias -AbortPollCallback.
# The dispatcher's -PollCallback, and the names 4.0 removed.
Reset-Harness
foreach ($apiName in 'PollCallback', 'AbortPollCallback') {
$apiFeed = @{ Given = $false; Polls = 0 }
$apiParams = @{
MaxConcurrent = 1
GroupProvider = { if ($apiFeed.Given) { return $null }; $apiFeed.Given = $true; return 'g' }.GetNewClosure()
JobBuilder = { param($g) return @(@{ FilePath = $cmdExe; Arguments = '/c exit 0' }) }.GetNewClosure()
JobFinalize = { param($job, $q) $null = Complete-PkProcess -Job $job }
}
$apiParams[$apiName] = { param($running) $apiFeed.Polls++ }.GetNewClosure()
$apiRun = Invoke-PkProcessDispatch @apiParams
Test-Assert ($apiFeed.Polls -gt 0 -and $apiRun.GroupResults.Count -eq 1) ("the dispatcher takes -" + $apiName + " (" + $apiFeed.Polls + " passes)")
$apiFeed = @{ Given = $false; Polls = 0 }
$apiParams = @{
MaxConcurrent = 1
GroupProvider = { if ($apiFeed.Given) { return $null }; $apiFeed.Given = $true; return 'g' }.GetNewClosure()
JobBuilder = { param($g) return @(@{ FilePath = $cmdExe; Arguments = '/c exit 0' }) }.GetNewClosure()
JobFinalize = { param($job, $q) $null = Complete-PkProcess -Job $job }
PollCallback = { param($running) $apiFeed.Polls++ }.GetNewClosure()
}
Test-Assert ((Get-Command Invoke-PkProcessDispatch).Parameters['PollCallback'].Aliases -contains 'AbortPollCallback') "-AbortPollCallback is an alias of -PollCallback"
$apiRun = Invoke-PkProcessDispatch @apiParams
Test-Assert ($apiFeed.Polls -gt 0 -and $apiRun.GroupResults.Count -eq 1) ("the dispatcher takes -PollCallback (" + $apiFeed.Polls + " passes)")
$threw = $null
try { $null = Invoke-PkProcessDispatch -AbortPollCallback { } -MaxConcurrent 1 -GroupProvider { } -JobBuilder { } -JobFinalize { } } catch { $threw = [string]$_ }
Test-Assert ($threw -like "*parameter name 'AbortPollCallback'*") ("its old name -AbortPollCallback is an error (" + $threw + ")")
$threw = $null
try { $null = Initialize-ParallelKit -MaxConcurrentProcesses 8 } catch { $threw = [string]$_ }
Test-Assert ($threw -like "*parameter name 'MaxConcurrentProcesses'*") ("Initialize-ParallelKit -MaxConcurrentProcesses is an error (" + $threw + ")")
Reset-Harness
Write-Host ""
}
Expand Down
Loading
Loading