Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v7.2.5] Try to stabilize a few tests that fail intermittently #17426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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