Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,43 @@

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)
}

}

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
}

Expand Down