Skip to content

Commit

Permalink
Updated thread job to version 1.1.2 (PowerShell#7522)
Browse files Browse the repository at this point in the history
Added fix to remove unneeded validation attribute for Arguments parameter, and made tests work with strict mode.
  • Loading branch information
PaulHigin authored and TravisEz13 committed Aug 15, 2018
1 parent 9655528 commit a213667
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion assets/files.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@
</Directory>
</Directory>
<Directory Id="dir37EBACBC570E49108415C3BA316EB66D" Name="ThreadJob">
<Directory Id="dirCB93DAC4CEB64A8583295B9AC4A79883" Name="1.1.1">
<Directory Id="dirCB93DAC4CEB64A8583295B9AC4A79883" Name="1.1.2">
<Component Id="cmp9ADDEE83EFD3497C804FDC6B93A58031" Guid="{9ADDEE83EFD3497C804FDC6B93A58031}">
<File Id="fil15E1EF74BF8C4AFFA6E9B53D8CF6E15E" KeyPath="yes" Source="$(env.ProductSourcePath)\Modules\ThreadJob\ThreadJob.dll" />
</Component>
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/PSGalleryModules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReference Include="PowerShellGet" Version="1.6.0" />
<PackageReference Include="Microsoft.PowerShell.Archive" Version="1.1.0.0" />
<PackageReference Include="PSReadLine" Version="2.0.0-beta2" />
<PackageReference Include="ThreadJob" Version="1.1.1" />
<PackageReference Include="ThreadJob" Version="1.1.2" />
</ItemGroup>

</Project>
48 changes: 22 additions & 26 deletions test/powershell/Modules/ThreadJob/ThreadJob.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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' {
Expand Down Expand Up @@ -156,15 +156,15 @@ 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"
}

It 'ThreadJob with ScriptFile and Initialization script' {

$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"
}

Expand Down Expand Up @@ -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 }
Expand All @@ -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' {
Expand All @@ -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
Expand All @@ -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
}
'@

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 $_" } }
Expand All @@ -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' {
Expand All @@ -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' {
Expand Down

0 comments on commit a213667

Please sign in to comment.