mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Update a few tests to make them more stable in CI (#16944)
This commit is contained in:
1 parent
df460b7275
commit
9b2d97e3e2
2 files changed
+14
-20
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user