Skip to content
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 @@ -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')
Expand All @@ -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()
}
}
}
}
Expand Down