Skip to content

Remoting and Job tests#4928

Merged
TravisEz13 merged 8 commits into
PowerShell:masterfrom
adityapatwardhan:RemotingTests
Oct 2, 2017
Merged

Remoting and Job tests#4928
TravisEz13 merged 8 commits into
PowerShell:masterfrom
adityapatwardhan:RemotingTests

Conversation

@adityapatwardhan
Copy link
Copy Markdown
Member

This should increase coverage under src/System.Management.Automation/engine/remoting substantially.

@msftclas
Copy link
Copy Markdown

msftclas commented Sep 27, 2017

CLA assistant check
All CLA requirements met.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this check removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ComputerName cannot be null due to ParameterValidation. So this.ComputerName == null is always false. Which makes the if always false due to the &&. Hence unreachable code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. Can you also remove the error message from RemotingErrorIdStrings.resx and RemotingErrorIdStrings.cs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am worried about race condition here. It is possible for the job to complete before the ValidateJobInfo script runs and cause false failures. I dislike adding 'sleep 1' to the job script because it slows down the test.
I think the best thing is to remove this test for the intermediate 'Running' state and just do the following test for 'Completed' state and check the result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not as concerned about this intermediate state race condition because the second Start-Job takes time. So we are probably Ok.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor comment. Should we use an AfterEach { Get-Job | Remove-Job -Force -EA Silently } block to clean up after each It block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This assumes the first job waiting one second will be the first to complete. This will be true most of the time but it is possible for a different job to complete first. I feel the test can allow '1', '2', '3' as the result and still be a good test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this added to ensure there is a PowerShell 6.0 endpoint available? Or just to ensure remoting is enabled? If so can you add a comment?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo ... "so that when"...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should be a "Feature" test. Or at least have the "Slow" tag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It takes about 10 seconds. I believe it is fast enough to be in CI. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure but the testing guidelines say most CI tests take less than one second and the "Slow" tag should be considered if a test takes longer. Since these are critical remoting functions it seems like we should leave them as CI tests, but probably should add the "Slow" tag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Feature" or "Slow" tag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These finish in about 12 seconds. I think that should be OK. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure but the testing guidelines say most CI tests take less than one second and the "Slow" tag should be considered if a test takes longer. Since these are critical remoting functions it seems like we should leave them as CI tests, but probably should add the "Slow" tag.

Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

This looks good to me. The only additional feedback I have is:
a. Please also remove InvokeDisconnectWithoutComputerName resource string in InvokeCommandCommand.cs.
b. Consider using 'Slow' tag on the slower remoting tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There seems to be some repetition here in each test case within this context. How about changing the BeforeEach to an AfterEach and removing lines 40, 48, etc...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AfterEach cleanup is needed within this Context as well.

Comment applies to all Context blocks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Organizational nitpick: This is a Receive-Job test that is included within the Wait-Job set of tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved. Good catch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would a check to make sure that none of the jobs threw errors make sense here too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The scriptblock { 1 + 1 } and string ' 1 + 1 ' are repeated throughout This is one of those readability vs changeability trade offs. Did you consider making them script variables?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I preferred readability. Likelihood of we needing to change is low. Your thoughts?

@mirichmo
Copy link
Copy Markdown
Member

mirichmo commented Sep 29, 2017

I've had a review going for a few days. I published the comments so that I can sync it based on your latest updates

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test doesn't actually test the NoRecurse functionality. There should be a child job and a check should be made to ensure that it gets the correct value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All jobs create a childjob which returns the result. Hence with NoRecurse we cannot get the result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer AfterEach for clean up. With BeforeEach, the last It will "leak" a Job that it should clean up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Please capitalize Get-Job

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an issue for this in the Pester repo? If so, please include a link

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need to do a deeper analysis to file an issue. It could be Pester or PowerShell scoping issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clean up should be done in an AfterEach. Remove-Job won't execute if the ValidateJobInfo test fails.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This session won't get cleaned up during test failure. Comment also applies to the other It's within this Context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. Used try/finally

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test doesn't validate that the scriptblock was run in the correct scope. It just validates that the scriptblock was run in a scope. It provides code coverage, but isn't really useful in terms of validating functionality as-is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. I set a variable in the script block and check the value after.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove-job?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added -AutoRemove.

@adityapatwardhan
Copy link
Copy Markdown
Member Author

@mirichmo Resolved all your comments. Please have another look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spelling

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you move this comment to line 271? It makes more sense there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved.

@adityapatwardhan
Copy link
Copy Markdown
Member Author

@mirichmo Resolved all feedback. Please have a look. Unrelated tests failing.

@TravisEz13
Copy link
Copy Markdown
Member

@mirichmo Can you update your review?

@TravisEz13 TravisEz13 merged commit 1e271ea into PowerShell:master Oct 2, 2017
@adityapatwardhan adityapatwardhan deleted the RemotingTests branch November 1, 2018 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants