Updated thread job to version 1.1.2 (#7522)

Added fix to remove unneeded validation attribute for Arguments parameter, and made tests work with strict mode.
This commit is contained in:
Paul Higinbotham
2018-08-14 17:09:48 -07:00
committed by Travis Plunk
parent 965552873c
commit a21366710c
3 changed files with 24 additions and 28 deletions
@@ -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' {