Skip to content

Commit

Permalink
Try to stabilize a few tests that fail intermittently (#17426)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 26, 2022
1 parent 580816a commit 0fe19c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Expand Up @@ -34,32 +34,26 @@ function Invoke-PSHostProcessScript {
[int] $Retry = 5 # Default retry of 5 times
)

$sb = {
# use $i as an incrementally growing pause based on the attempt number
# so that it's more likely to succeed.
$commandStr = @'
Start-Sleep -Seconds {0}
Enter-PSHostProcess {1} -ErrorAction Stop
$commandStr = @'
Enter-PSHostProcess {0} -ErrorAction Stop
$PID
Exit-PSHostProcess
'@ -f $i, $ArgumentString

($commandStr | & $powershell -c -) -eq $Id
}
'@ -f $ArgumentString

$result = $false
$failures = 0
foreach ($i in 1..$Retry) {
if ($sb.Invoke()) {
$result = $true
# use $i as an incrementally growing pause based on the attempt number
# so that it's more likely to succeed.
Start-Sleep -Seconds $i

$result = ($commandStr | & $powershell -noprofile -c -) -eq $Id
if ($result) {
break
}

$failures++
}

if($failures) {
Write-Warning "Enter-PSHostProcess script failed $i out of $Retry times."
if ($i -gt 1) {
Write-Verbose -Verbose "Enter-PSHostProcess script failed $i out of $Retry times."
}

$result
Expand Down Expand Up @@ -99,7 +93,7 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {

# This will enter and exit another process
Invoke-PSHostProcessScript -ArgumentString "-Id $pwshId" -Id $pwshId |
Should -BeTrue -Because "The script was able to enter another process and grab the pid of '$pwshId'."
Should -BeTrue -Because "The script was able to enter another process and grab the pid of '$pwshId'"

# Re-enter and exit the other process
Invoke-PSHostProcessScript -ArgumentString "-Id $pwshId" -Id $pwshId |
Expand All @@ -109,7 +103,7 @@ Describe "Enter-PSHostProcess tests" -Tag Feature {
It "Can enter, exit, and re-enter another Windows PowerShell PSHost" -Skip:(!$IsWindows) {
# Start a PowerShell job where the first thing it does is return $PID. After that, spin forever.
# We will use this job as the target process for Enter-PSHostProcess
$powershellJob = Start-Job {
$powershellJob = Start-Job -PSVersion 5.1 {
$PID
while ($true) {
Start-Sleep -Seconds 30 | Out-Null
Expand Down
Expand Up @@ -44,7 +44,7 @@ Describe 'Get-WinEvent' -Tags "CI" {
# we sample the first 20 results, as this could be very large
$results = Get-WinEvent -provider $providerForTests.Name -max 20
foreach($event in $results ) {
$event.providername | Should -BeExactly $providerForTests.name
$event.providername | Should -Be $providerForTests.name
}
}
It 'Get-WinEvent can get events via logname' {
Expand Down

0 comments on commit 0fe19c1

Please sign in to comment.