diff --git a/assets/files.wxs b/assets/files.wxs index 17ab216bb2e..4275b3caf28 100644 --- a/assets/files.wxs +++ b/assets/files.wxs @@ -1840,7 +1840,7 @@ - + diff --git a/src/Modules/PSGalleryModules.csproj b/src/Modules/PSGalleryModules.csproj index 3ba7aebf459..41453a25af2 100644 --- a/src/Modules/PSGalleryModules.csproj +++ b/src/Modules/PSGalleryModules.csproj @@ -7,7 +7,7 @@ - + diff --git a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 index bbe34d694cf..def17e706fe 100644 --- a/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 +++ b/test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1 @@ -70,7 +70,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { ) $iteration = 20 - while (((Get-Runspace).Count -ne $expectedRSCount) -and ($iteration-- -gt 0)) + while ((@(Get-Runspace).Count -ne $expectedRSCount) -and ($iteration-- -gt 0)) { Start-Sleep -Milliseconds 100 } @@ -79,7 +79,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { } AfterEach { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force } It 'ThreadJob with ScriptBlock' { @@ -156,7 +156,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $job = Start-ThreadJob -FilePath $scriptFilePath1 $results = $job | Receive-Job -Wait - $results.Count | Should -Be 10 + $results | Should -HaveCount 10 $results[9] | Should -Be "Hello 9" } @@ -164,7 +164,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $job = Start-ThreadJob -FilePath $scriptFilePath1 -Initialization { "Goodbye" } $results = $job | Receive-Job -Wait - $results.Count | Should -Be 11 + $results | Should -HaveCount 11 $results[0] | Should -Be "Goodbye" } @@ -241,7 +241,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { try { # Start four thread jobs with ThrottleLimit set to two - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force $job1 = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } -ThrottleLimit 2 $job2 = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } $job3 = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } @@ -250,19 +250,15 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { # Allow jobs to start Wait-ForJobRunning $job2 - $numRunningThreadJobs = (Get-Job | where { ($_.PSJobTypeName -eq "ThreadJob") -and ($_.State -eq "Running") }).Count - $numQueuedThreadJobs = (Get-Job | where { ($_.PSJobTypeName -eq "ThreadJob") -and ($_.State -eq "NotStarted") }).Count - - $numRunningThreadJobs | Should -Be 2 - $numQueuedThreadJobs | Should -Be 2 + Get-Job | Where-Object { ($_.PSJobTypeName -eq "ThreadJob") -and ($_.State -eq "Running") } | Should -HaveCount 2 + Get-Job | Where-Object { ($_.PSJobTypeName -eq "ThreadJob") -and ($_.State -eq "NotStarted") } | Should -HaveCount 2 } finally { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force } - $numThreadJobs = (Get-Job | where PSJobTypeName -eq "ThreadJob").Count - $numThreadJobs | Should -Be 0 + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Should -HaveCount 0 } It 'ThreadJob Runspaces should be cleaned up at completion' { @@ -271,8 +267,8 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { try { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force - $rsStartCount = (Get-Runspace).Count + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + $rsStartCount = @(Get-Runspace).Count # Start four thread jobs with ThrottleLimit set to two $Job1 = Start-ThreadJob -ScriptBlock { "Hello 1!" } -ThrottleLimit 5 @@ -285,11 +281,11 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { # Allow for runspace clean up to happen Wait-ForExpectedRSCount $rsStartCount - Write-Output ((Get-Runspace).Count -eq $rsStartCount) + Write-Output (@(Get-Runspace).Count -eq $rsStartCount) } finally { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force } '@ @@ -302,8 +298,8 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $script = $WaitForCountFnScript + @' try { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force - $rsStartCount = (Get-Runspace).Count + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + $rsStartCount = @(Get-Runspace).Count # Start four thread jobs with ThrottleLimit set to two $Job1 = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } -ThrottleLimit 2 @@ -312,22 +308,22 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $job4 = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } Wait-ForExpectedRSCount ($rsStartCount + 4) - Write-Output ((Get-Runspace).Count -eq ($rsStartCount + 4)) + Write-Output (@(Get-Runspace).Count -eq ($rsStartCount + 4)) # Stop two jobs $job1 | Remove-Job -Force $job3 | Remove-Job -Force Wait-ForExpectedRSCount ($rsStartCount + 2) - Write-Output ((Get-Runspace).Count -eq ($rsStartCount + 2)) + Write-Output (@(Get-Runspace).Count -eq ($rsStartCount + 2)) } finally { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force } Wait-ForExpectedRSCount $rsStartCount - Write-Output ((Get-Runspace).Count -eq $rsStartCount) + Write-Output (@(Get-Runspace).Count -eq $rsStartCount) '@ $result = & "$PSHOME/pwsh" -c $script @@ -336,7 +332,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { It 'ThreadJob jobs should work with Receive-Job -AutoRemoveJob' { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force $job1 = Start-ThreadJob -ScriptBlock { 1..2 | foreach { Start-Sleep -Milliseconds 100; "Output $_" } } -ThrottleLimit 5 $job2 = Start-ThreadJob -ScriptBlock { 1..2 | foreach { Start-Sleep -Milliseconds 100; "Output $_" } } @@ -345,7 +341,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { $null = $job1,$job2,$job3,$job4 | Receive-Job -Wait -AutoRemoveJob - (Get-Job | where PSJobTypeName -eq "ThreadJob").Count | Should -Be 0 + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Should -HaveCount 0 } It 'ThreadJob jobs should run in FullLanguage mode by default' { @@ -358,7 +354,7 @@ Describe 'Basic ThreadJob Tests' -Tags 'CI' { Describe 'Job2 class API tests' -Tags 'CI' { AfterEach { - Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force + Get-Job | Where-Object PSJobTypeName -eq "ThreadJob" | Remove-Job -Force } It 'Verifies StopJob API' {