Release v0.6.46: bundle StayHere activity utility
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
param([Parameter(Mandatory=$true)][string]$Executable)
|
||||
$ErrorActionPreference='Stop'
|
||||
function Command([string]$Argument) {
|
||||
$commandProcess=Start-Process -FilePath $Executable -ArgumentList $Argument -WindowStyle Hidden -PassThru
|
||||
try {
|
||||
$null=$commandProcess.Handle
|
||||
$commandProcess.WaitForExit()
|
||||
return $commandProcess.ExitCode
|
||||
} finally { $commandProcess.Dispose() }
|
||||
}
|
||||
if ((Command '--status') -ne 3) { throw 'An isolated StayHere test instance is already running' }
|
||||
$process=Start-Process -FilePath $Executable -WindowStyle Hidden -PassThru
|
||||
$null=$process.Handle
|
||||
try {
|
||||
$ready=$false
|
||||
for($i=0;$i -lt 20;$i++) {
|
||||
if((Command '--status') -eq 1){$ready=$true;break}
|
||||
Start-Sleep -Milliseconds 50
|
||||
}
|
||||
if(!$ready){throw 'StayHere did not start enabled'}
|
||||
if((Command '--pause') -ne 0 -or (Command '--status') -ne 2){throw 'StayHere pause failed'}
|
||||
if((Command '--resume') -ne 0 -or (Command '--status') -ne 1){throw 'StayHere resume failed'}
|
||||
if((Command '--exit') -ne 0 -or !$process.WaitForExit(3000)){throw 'StayHere exit failed'}
|
||||
if((Command '--status') -ne 3){throw 'StayHere instance remained after exit'}
|
||||
Write-Output 'Passed isolated StayHere start/status/pause/resume/exit checks'
|
||||
} finally {
|
||||
if(!$process.HasExited){$null=Command '--exit';if(!$process.WaitForExit(3000)){$process.Kill()}}
|
||||
$process.Dispose()
|
||||
}
|
||||
Reference in New Issue
Block a user