mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Update a few tests to make them more stable in CI (#16944)
This commit is contained in:
@@ -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
|
||||
@@ -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 |
|
||||
@@ -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
|
||||
|
||||
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user