Use dedicated threads to read the redirected output and error streams from the child process for out-of-proc jobs (#11713)

This commit is contained in:
Dongbo Wang
2020-03-28 15:44:23 +05:00
committed by GitHub
parent 515511094d
commit 1ec7c826f0
2 changed files with 135 additions and 39 deletions
+54
View File
@@ -338,4 +338,58 @@ Describe 'Basic Job Tests' -Tags 'Feature' {
ValidateJobInfo -job $jobToStop -state 'Stopped' -hasMoreData $false
}
}
Context 'Background pwsh process should terminate after job is done' {
It "Can clean up background pwsh process after job is done" {
$job = Start-Job { $pid }
$processId = Receive-Job $job -Wait
try {
$process = Get-Process -Id $processId -ErrorAction Stop
Wait-UntilTrue { $process.HasExited } -IntervalInMilliseconds 300 | Should -BeTrue
} catch {
$_.FullyQualifiedErrorId | Should -BeExactly 'NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand'
}
Remove-Job $job -Force
}
It "Can clean up background pwsh process when job is stopped" {
$job = Start-Job { $pid; Start-Sleep -Second 10 }
# Wait for the pid to be received.
Wait-UntilTrue { [bool](Receive-Job $job -Keep) } | Should -BeTrue
$processId = Receive-Job $job
# Stop the job and wait for the cleanup to finish.
Stop-Job $job
try {
$process = Get-Process -Id $processId -ErrorAction Stop
Wait-UntilTrue { $process.HasExited } -IntervalInMilliseconds 300 | Should -BeTrue
} catch {
$_.FullyQualifiedErrorId | Should -BeExactly 'NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand'
}
Remove-Job $job -Force
}
It "Can clean up background pwsh process when job is removed" {
$job = Start-Job { $pid; Start-Sleep -Second 10 }
# Wait for the pid to be received.
Wait-UntilTrue { [bool](Receive-Job $job -Keep) } | Should -BeTrue
$processId = Receive-Job $job
# Remove the job and wait for the cleanup to finish.
Remove-Job $job -Force
try {
$process = Get-Process -Id $processId -ErrorAction Stop
Wait-UntilTrue { $process.HasExited } -IntervalInMilliseconds 300 | Should -BeTrue
} catch {
$_.FullyQualifiedErrorId | Should -BeExactly 'NoProcessFoundForGivenId,Microsoft.PowerShell.Commands.GetProcessCommand'
}
}
}
}