Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ThreadJob module package and tests #7169

Merged
merged 5 commits into from
Jul 6, 2018
Merged

Add ThreadJob module package and tests #7169

merged 5 commits into from
Jul 6, 2018

Conversation

PaulHigin
Copy link
Contributor

PR Summary

This adds the ThreadJob module package from the PSGallery, along with Pester tests

PR Checklist

@PaulHigin PaulHigin requested review from SteveL-MSFT and removed request for daxian-dbw, TravisEz13, anmenaga and adityapatwardhan June 25, 2018 18:32
@PaulHigin PaulHigin added the WG-Engine core PowerShell engine, interpreter, and runtime label Jun 25, 2018
@PaulHigin PaulHigin added this to the 6.1.0-Consider milestone Jun 25, 2018
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

$results | Should Be "Hello There 60"
}

It 'ThreadJob with terminating error' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a test for non-terminating error?
... and, in general, tests for verifying that objects in all PS streams (Verbose, Debug, Error, ...) are returned correctly from ThreadJobs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not intended to be an exhaustive list of job tests, but I have added data stream tests.

{
# Start four thread jobs with ThrottleLimit set to two
Get-Job | where PSJobTypeName -eq "ThreadJob" | Remove-Job -Force
Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 60 } -ThrottleLimit 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to review; but for my education:
The ThrottleLimit syntax looks interesting; couple of questions:

  • What is the scope of ThrottleLimit ? e.g. "all threadjobs in current script" ?
  • How do subsequent Start-ThreadJob's in the script know under what ThrottleLimit they operate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throttle limit is per PowerShell session so it limits all concurrent threadjobs created in that session. The queue is static (singleton). I currently don't have a way to get the current throttle limit value ... you just set it. But something like that can be added.

See source code for more details:
https://github.com/PaulHigin/PSThreadJob/blob/master/ThreadJob/ThreadJob/PSThreadJob.cs#L18

}
}

Describe 'Job2 Tests' -Tags 'CI' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename the Describe to "Job2 class API tests" or something like this.
For an unfamiliar person it is not clear what 'Job2' is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.


$job = Start-ThreadJob -ScriptBlock { "Hello" }
$results = $job | Receive-Job -Wait
$results | Should be "Hello"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Pester 4 syntax?

$results | Should -Be "Hello"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build only pulls in Pester 3.3.9 right now which does not support this syntax. We should wait to update tests until the default pester version supports the new syntax.


It 'ThreadJob with terminating error' {

$job = Start-ThreadJob -ScriptBlock { throw "MyError!" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test for a non-terminating error where some objects are returned and 1 non-terminating error is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outside the scope of this change. Please create an Issue for adding more threadjob tests.


It 'Verifies terminating job error' {

$job = Start-ThreadJob -ScriptBlock { throw "My Job Error!" } | Wait-Job
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a slightly different test since it involves Receive-Job, so I'd like to keep it.

$job3 | Remove-Job -Force

(Get-Runspace).Count | Should Be ($rsStartCount + 2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but will keep for readability.

Describe 'Job2 Tests' -Tags 'CI' {

AfterEach {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but will keep for readability.

}

AfterEach {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but will keep for readability.

@TravisEz13
Copy link
Member

@adityapatwardhan can you update your review?


It 'ThreadJob with ScriptBlock and Initialization script' {

$job = Start-ThreadJob -ScriptBlock { "Goodbye" } -InitializationScript { "Hello" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this actually take a script (i.e. a path to a script) or just a scriptblock. If only takes a scriptblock, then the parameter should probably be named "-InitializationScriptBlock".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It just takes a scriptblock. But I used the same parameter name as what Start-Job uses, which also just takes a scriptblock. So for consistency we should probably keep the parameter name as is (or change both).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking of consistency between -ScriptBlock and -InitialScriptBlock. But following what existing commands do is probably fine.

@PaulHigin
Copy link
Contributor Author

@TravisEz13 I just found a bug in this version of ThreadJob. Please hold off merging until I have a fix ready. Thanks.

@TravisEz13 TravisEz13 changed the title Add ThreadJob module package and tests WIP Add ThreadJob module package and tests Jun 27, 2018
@TravisEz13
Copy link
Member

@PaulHigin to prevent maintainers from merging, rename your PR with WIP in front of the title. remove WIP to unblock. This will fail the Work In Progress (WIP), CI test immediately.

@PaulHigin PaulHigin changed the title WIP Add ThreadJob module package and tests Add ThreadJob module package and tests Jun 29, 2018
@PaulHigin
Copy link
Contributor Author

I have fixed the bug, updated tests, and updated the package with the new version. Please take a look.

@PaulHigin
Copy link
Contributor Author

@adityapatwardhan Can you please review changes?


# Get-Job -Filter is not supported
$result = Get-Job -Filter @{Id = ($job.Id)} 3>$null
$result | Should -Be $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Should -BeNullOrEmpty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

assets/files.wxs Outdated
@@ -1826,7 +1826,7 @@
</Directory>
</Directory>
<Directory Id="dir37EBACBC570E49108415C3BA316EB66D" Name="ThreadJob">
<Directory Id="dirCB93DAC4CEB64A8583295B9AC4A79883" Name="1.1.0">
<Directory Id="dirCB93DAC4CEB64A8583295B9AC4A79883" Name="1.1.1">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue for this PR. We should consider not putting the modules in a version folder. If we have to update the modules, this will make patching very difficult.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #7236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants