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 @@ -133,7 +133,23 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {
$rs.Open()
$ps = [powershell]::Create()
$ps.Runspace = $rs
$ps.AddScript('$pid').Invoke() | Should -Be $pwshId
$ps.AddScript('$pid')

[int]$retry = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Wait-UntilTrue from HelpersCommon.psm1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, maybe add a retry function on HelpersCommon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked out a Invoke-ScriptBlockWithRetry function, but it doesn't save much and makes the code harder to understand since I need to pass two types of information back.

$result = $null
$errorMsg = "Exception: "
while ($retry -lt 5 -and $result -eq $null) {
try {
$result = $ps.Invoke()
}
catch [System.Management.Automation.Runspaces.InvalidRunspaceStateException] {
$errorMsg += $_.Exception.InnerException.Message + "; "
$retry++
Start-Sleep -Milliseconds 100
}
}

$result | Should -Be $pwshId -Because $errorMsg
} finally {
$rs.Dispose()
$ps.Dispose()
Expand Down