Check state and report reason if it's not "opened" (#11574)

This commit is contained in:
Tyler James Leonhardt 2020-01-30 14:42:51 -08:00 committed by GitHub
parent 476a2d1dac
commit 6911aa3794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -131,7 +131,22 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {
$npInfo = [System.Management.Automation.Runspaces.NamedPipeConnectionInfo]::new($pwshId)
$rs = [runspacefactory]::CreateRunspace($npInfo)
$rs.Open()
# Try to open the runspace while tracing.
$splat = @{
Name = "RunspaceInit"
Expression = {$Input.Open()}
PSHost = $true
ListenerOption = [System.Diagnostics.TraceOptions]::Callstack
FilePath = "$TestDrive/$([System.IO.Path]::GetRandomFileName()).log"
InputObject = $rs
}
Trace-Command @splat
# If opening the runspace fails, then print out the trace with the callstack
Wait-UntilTrue { $rs.RunspaceStateInfo.State -eq [System.Management.Automation.Runspaces.RunspaceState]::Opened } |
Should -BeTrue -Because (get-content $splat.FilePath -Raw)
$ps = [powershell]::Create()
$ps.Runspace = $rs
$ps.AddScript('$PID')
@ -152,8 +167,14 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {
$result | Should -Be $pwshId -Because $errorMsg
} finally {
$rs.Dispose()
$ps.Dispose()
# Clean up disposables
if ($rs) {
$rs.Dispose()
}
if ($ps) {
$ps.Dispose()
}
}
}
}