-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix Enter-PSHostProcess tests flakiness #9007
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
Fix Enter-PSHostProcess tests flakiness #9007
Conversation
|
Just to be sure, I'd like to run CI a few times to see if the failure shows up. I'm going to 😴but if someone in some other place (where it's not late) wants to kick them off again by adding commits or something, that'd be helpful! |
|
I'd can restart but it is already failed :-( |
|
Jeez... OK... Ran this like 20 times in a container and couldn't repro the issue. Back to the drawing board... |
|
I can repro the same problem if I do this: > "Enter-PSHostProcess -Id 40328 -ErrorAction Stop
`$pid
Exit-PSHostProcess" > test.ps1
> ./test.ps1 |
|
Looks tricky! |
|
The odd thing is... I added "Enter-PSHostProcess -Id $($pwsh.Id) -ErrorAction Stop
`$pid
Exit-PSHostProcess" | pwsh -c - | Should -Be $pwsh.IdIn my local testing... I noticed that:
1432 was typically the |
|
@TylerLeonhardt Maybe #1995? |
|
@TylerLeonhardt does this repro the issue? @'
try {{
Enter-PSHostProcess -Id {0} -ErrorAction Stop
$pid
}}
finally {{
Exit-PSHostProcess
}}
'@ -f $pwsh.Id | pwsh -c - | Should -Be $pwsh.IdIn other words, is the -ErrorAction Stop behaving as we expect? |
|
|
||
| It "Should throw if CustomPipeName is too long on Linux or macOS" { | ||
| It "Should throw if CustomPipeName is too long on Linux or macOS" -Skip:($IsWindows) { | ||
| $longPipeName = "DoggoipsumwaggywagssmolborkingdoggowithalongsnootforpatsdoingmeafrightenporgoYapperporgolongwatershoobcloudsbigolpupperlengthboy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a thing?
(just wondering)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because on unix they're not called "Named Pipes" they're called "UNIX domain sockets" which have a limit on macOS and Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant $longPipeName = "DoggoipsumwaggywagssmolborkingdoggowithalongsnootforpatsdoingmeafrightenporgoYapperporgolongwatershoobcloudsbigolpupperlengthboy"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to generate needed length and add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
|
@TylerLeonhardt I suggest replace "-c" with "-file" to avoid escaping problem. |
test.ps1
Outdated
| @@ -0,0 +1,3 @@ | |||
| Enter-PSHostProcess -Id 40328 -ErrorAction Stop | |||
| $pid | |||
| Exit-PSHostProcess | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do. Still getting data. moved to WIP
Sorry, where exactly? |
| }} | ||
| finally {{ | ||
| Exit-PSHostProcess | ||
| }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double braces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need this for template strings to escape { and } otherwise it throws a bad formatting exception
|
jeez... |
|
|
||
| } | ||
| It "Can enter, exit, and re-enter another PSHost" { | ||
| # $pwsh = Start-PSProcess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably just hold off on reviewing. This issue only repros in CI... so it'll be a lot of trial and error.
When I remove WIP, you can review for real.
Open to suggestions on how to fix the tests though 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion was above - use "-file" parameter and put the temporary test script in file.
|
If this succeeds CI, please restart a few times. I need 😴 If this works, I'll need to add a test to |
|
it... passed once so far. Triggered again with some comments... now time for bed. |
|
I restarted CI-windows as you ask (previous was Ok). |
test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
Show resolved
Hide resolved
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| function Wait-JobPid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should have a count limit in the loop, in case the script fails for some reason, and throw on failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added timeout
test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
Show resolved
Hide resolved
|
I spoke to @PaulHigin about this and we agreed that since the tests have been reliable in this PR, we'll keep them in. If they become a problem again, we can remove the ones that use |
…ardt/PowerShell into fix-enter-pshostprocess-tests
| $pipePath = Get-PipePath $pipeName | ||
|
|
||
| # The pipePath should be created by the time the -Command is executed. | ||
| pwsh -CustomPipeName $pipeName -Command "Test-Path '$pipePath'" | Should -BeTrue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $powershell instead. Using pwsh will call the installed pwsh on the system, not the one which we build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If what you say is true, then none of my CustomPipeName tests would be passing, right? I'm willing to change it though. Is that a magic variable or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably set during the build or on test initialization with Start-PSPester, I'd imagine. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see what you're saying now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed this so it's consistent
|
|
||
| "`$pid" | & $powershell -CustomPipeName $longPipeName -c - | ||
| # 64 is the ExitCode for BadCommandLineParameter | ||
| $LASTEXITCODE | Should -Be 64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check for FullyQualifiedErrorId that is not localized.
| Should -BeTrue -Because "The script was able to re-enter another process and grab the pid of '$powershellId'." | ||
|
|
||
| } finally { | ||
| $powershellJob | Stop-Process -Force -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Stop-Job | Remove-Job instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're totally right. Added.
| $ps.AddScript('$pid').Invoke() | Should -Be $pwsh.Id | ||
| $ps.AddScript('$pid').Invoke() | Should -Be $pwshId | ||
| } finally { | ||
| $rs.Dispose() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add $ps.Dispose()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
@TylerLeonhardt - To fix the static analysis CI - update the link to https://www.itprotoday.com/powershell/powershell-basics-remote-management |
|
Restarted Windows CI |
|
@TravisEz13 can you update your review? |
…ardt/PowerShell into fix-enter-pshostprocess-tests
|
@TylerLeonhardt Just realized the tests that were changed are tagged as |
…ardt/PowerShell into fix-enter-pshostprocess-tests
|
triggered |
|
This has become unreliable again. I have filed #11168 |
PR Summary
This PR totally refactors the
Enter-PSHostProcesstests.fixes #8971
PR Context
The biggest change was that rather then sharing an instance of PowerShell, the tests will each have their own instance of PowerShell to interact with.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.[feature]to your commit messages if the change is significant or affects feature tests