mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Multiple test fixes and improved logging for fragile tests (#9569)
This commit is contained in:
@@ -45,19 +45,21 @@ $rs.Open()
|
||||
$ps = [powershell]::Create()
|
||||
$ps.RunspacePool = $rs
|
||||
$null = $ps.AddScript(1).Invoke()
|
||||
write-host should_not_stop_responding_at_exit
|
||||
"should_not_stop_responding_at_exit"
|
||||
exit
|
||||
'@
|
||||
$process = Start-Process pwsh -ArgumentList $command -PassThru
|
||||
$outputFile = New-Item -Path $TestDrive\output.txt -ItemType File
|
||||
$process = Start-Process pwsh -ArgumentList $command -PassThru -RedirectStandardOutput $outputFile
|
||||
Wait-UntilTrue -sb { $process.HasExited } -TimeoutInMilliseconds 5000 -IntervalInMilliseconds 1000 | Should -BeTrue
|
||||
$hasExited = $process.HasExited
|
||||
|
||||
$expect = "powershell process exits in 5 seconds"
|
||||
if (-not $process.HasExited) {
|
||||
Stop-Process -InputObject $process -Force -ErrorAction SilentlyContinue
|
||||
"powershell process doesn't exit in 5 seconds" | Should -Be $expect
|
||||
} else {
|
||||
$expect | Should -Be $expect
|
||||
$verboseMessage = Get-Content $outputFile
|
||||
|
||||
if (-not $hasExited) {
|
||||
Stop-Process $process -Force
|
||||
}
|
||||
|
||||
$hasExited | Should -BeTrue -Because "Process did not exit in 5 seconds as: $verboseMessage"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,10 +207,14 @@ try {
|
||||
try {
|
||||
$ir = $ps.AddScript("Start-Sleep -Seconds 60").InvokeAsync()
|
||||
Wait-UntilTrue { $ps.InvocationStateInfo.State -eq [System.Management.Automation.PSInvocationState]::Running } | Should -BeTrue
|
||||
$ps.InvocationStateInfo.State | Should -Be 'Running'
|
||||
Start-Sleep -Seconds 1 # add a sleep to wait for pipeline to start executing the command.
|
||||
$sr = $ps.StopAsync($null, $null)
|
||||
[System.Threading.Tasks.Task]::WaitAll(@($sr))
|
||||
$ps.Streams.Error | Should -HaveCount 0 -Because ($ps.Streams.Error | Out-String)
|
||||
$ps.Commands.Commands.commandtext | Should -Be "Start-Sleep -Seconds 60"
|
||||
$sr.IsCompletedSuccessfully | Should -Be $true
|
||||
$ir.IsFaulted | Should -Be $true
|
||||
$ir.IsFaulted | Should -Be $true -Because ($ir | Format-List -Force * | Out-String)
|
||||
$ir.Exception -is [System.AggregateException] | Should -Be $true
|
||||
$ir.Exception.InnerException -is [System.Management.Automation.PipelineStoppedException] | Should -Be $true
|
||||
$ps.InvocationStateInfo.State | Should -Be ([System.Management.Automation.PSInvocationState]::Stopped)
|
||||
|
||||
@@ -49,7 +49,7 @@ Describe 'Get-Help -Online opens the default web browser and navigates to the cm
|
||||
|
||||
$skipTest = [System.Management.Automation.Platform]::IsIoT -or
|
||||
[System.Management.Automation.Platform]::IsNanoServer -or
|
||||
$env:__InContainer -eq 1
|
||||
$env:__INCONTAINER -eq 1
|
||||
|
||||
# this code is a workaround for issue: https://github.com/PowerShell/PowerShell/issues/3079
|
||||
if((-not ($skipTest)) -and $IsWindows)
|
||||
|
||||
Reference in New Issue
Block a user