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
7 changes: 7 additions & 0 deletions ParallelKit.Harness.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ $sw = [System.Diagnostics.Stopwatch]::StartNew()
try { $null = Invoke-PkProcessWithTimeout -FilePath $pingExe -Arguments '-n 30 127.0.0.1' -TimeoutMs 800 } catch { $threw = ($_.ToString() -like '*did not exit within*') }
$sw.Stop()
Test-Assert ($threw -and $sw.Elapsed.TotalSeconds -lt 6) "a process that overruns its time limit is killed and reported"
# A -TimeoutMs below 1 is refused before anything starts, not taken as a
# limit that's already used up.
foreach ($badMs in 0, -5) {
$badMsError = $null
try { $null = Invoke-PkProcessWithTimeout -FilePath $cmdExe -Arguments '/c exit 0' -TimeoutMs $badMs } catch { $badMsError = $_.ToString() }
Test-Assert ($badMsError -like '*-TimeoutMs must be at least 1*') ("-TimeoutMs " + $badMs + " is refused with a clear message (error: " + $badMsError + ")")
}
$threw = $false
try { $null = Start-PkProcess -FilePath 'C:\no\such\program.exe' } catch { $threw = ($_.ToString() -like "*could not start*") }
Test-Assert $threw "a program that can't be started throws a clear error (not a silent null)"
Expand Down
4 changes: 3 additions & 1 deletion ParallelKit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ function Invoke-PkProcessWithTimeout {
# Its command line: one string, passed exactly as written, or a list, each
# element one argument, quoted for you (see ConvertTo-PkArgumentString).
# .PARAMETER TimeoutMs
# The time limit in milliseconds (default 60000).
# The time limit in milliseconds (default 60000), at least 1.
# .PARAMETER StreamTimeoutMs
# How long to wait for the output after the program exits (default 15000).
# .PARAMETER WorkingDirectory
Expand All @@ -1279,6 +1279,8 @@ function Invoke-PkProcessWithTimeout {
$OutputEncoding = $null,
[switch]$IgnoreAbort
)
# Checked before starting anything: 0 or less would kill the program at once.
if ($TimeoutMs -lt 1) { throw ("Invoke-PkProcessWithTimeout: -TimeoutMs must be at least 1 (got " + $TimeoutMs + "). It's the program's time limit in milliseconds.") }
$job = Start-PkProcessCore -FilePath $FilePath -Arguments $Arguments -WorkingDirectory $WorkingDirectory -OutputEncoding $OutputEncoding -CallerState $PSCmdlet.SessionState
try {
# Short slices, so an abort or cancel is noticed within a moment.
Expand Down
Loading