Fix Enter-PSHostProcess test to wait until runspace is ready before attempting to enter (#8725)

This fixes CI test failure in Windows build.
This commit is contained in:
Steve Lee 2019-01-23 15:07:34 -08:00 committed by Andrew
parent 4a1fc4b382
commit 3a8205018e

View file

@ -3,16 +3,19 @@
Describe "Enter-PSHostProcess tests" -Tag Feature {
BeforeAll {
$pwsh_started = New-TemporaryFile
$si = [System.Diagnostics.ProcessStartInfo]::new()
$si.FileName = "pwsh"
$si.Arguments = "-noexit"
$si.Arguments = "-noexit -command 'pwsh' > '$pwsh_started'"
$si.RedirectStandardInput = $true
$si.RedirectStandardOutput = $true
$si.RedirectStandardError = $true
$pwsh = [System.Diagnostics.Process]::Start($si)
if ($IsWindows) {
$powershell_started = New-TemporaryFile
$si.FileName = "powershell"
$si.Arguments = "-noexit -command 'powershell' >'$powershell_started'"
$powershell = [System.Diagnostics.Process]::Start($si)
}
@ -20,17 +23,23 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {
AfterAll {
$pwsh | Stop-Process
Remove-Item $pwsh_started -Force -ErrorAction SilentlyContinue
if ($IsWindows) {
$powershell | Stop-Process
Remove-Item $powershell_started -Force -ErrorAction SilentlyContinue
}
}
It "Can enter and exit another PSHost" {
Wait-UntilTrue { Test-Path $pwsh_started }
"enter-pshostprocess -id $($pwsh.Id)`n`$pid`nexit-pshostprocess" | pwsh -c - | Should -Be $pwsh.Id
}
It "Can enter and exit another Windows PowerShell PSHost" -Skip:(!$IsWindows) {
Wait-UntilTrue { Test-Path $powershell_started }
"enter-pshostprocess -id $($powershell.Id)`n`$pid`nexit-pshostprocess" | pwsh -c - | Should -Be $powershell.Id
}