From 3a8205018e8e543db339012e498560193ab601bd Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 23 Jan 2019 15:07:34 -0800 Subject: [PATCH] Fix Enter-PSHostProcess test to wait until runspace is ready before attempting to enter (#8725) This fixes CI test failure in Windows build. --- .../Enter-PSHostProcess.Tests.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1 index 1b2668391..88122c05b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1 @@ -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 }