-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix race condition in tests #7819
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
Conversation
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.
these is no guarantee that this will take a significant about of time. It may finish before you stop it.
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.
@JamesWTruher Can you review?
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.
these is no guarantee
Yes, I'd remove the tests - I do not see a way to make these tests reliable. If we just add a hook with an infinite loop...
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.
The intent of the test is to cover the StopProcessing code path as identified by code coverage. I wonder if we can just have at test hook in the cmdlet so that ProcessRecord() doesn't return if the test hook is in place. Therefore we can call Stop() so that the StopProcessing code path gets exercised?
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.
Seems like the implementation would be for ProcessRecord to Sleep for enough time that we are certain enough that we can stop it. This could also mean that we can get one object and process it instead of trying to process a lot of records trying to make it take a long time.
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.
Test hook added.
Sleep suspend current thread. So I used only short sleep to slow down a cmdlet.
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 have similar concerns here about test reliability
|
Reopen to restart Ci Appveyor. |
|
Reopen to restart Ci Appveyor. |
|
@iSazonov Do you have a Microsoft account? I can give you permissions to restart the Azure Pipelines if you give me a Microsoft account. feel free to send it to Steve or my work email. |
|
@TravisEz13 I sent. |
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 don't think this sleep is needed. There was a concern that the cmdlet would finish successfully before the stop of the pipeline got issued. I think they way to solve that is to have another check at the end of ProcessRecord() where if the test hook is enabled, just have it sleep and not finish.
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.
Stopping doesn't work on sleeping runspace. So idea is only slow down the cycle and make many interations.
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.
Ok, perhaps 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.
Done.
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.
Ok, perhaps add a comment?
861e0c2 to
dddfaa2
Compare
JamesWTruher
left 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.
Generally, I'm in favor of more test hooks, but I'm not a fan of extra verbosity. My only real objection is the hard coding of the timeout duration. I think that should be testhook supplied value.
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 would be happier if this value was in the testhook (ala TestStopComputerResults). This would enable us to change the duration easily, and even specific to a particular test.
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.
Done.
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.
what are you trying to achieve with the WriteVerbose? I'm not sure there's much value here and I would rather reduce the chatty output.
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.
The verbose message here is used to tell the test that the cmdlet has started so that it can issue the stop. Otherwise there's a window where stop is issued before the cmdlet under test has started.
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.
Yes, we need an event to start the stopping.
(We could use another test hook for the flag.)
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.
As this is a general purpose helper, I'm wondering whether this should be | Should -Not -Be "Running"
some of the states might be "failed" or "disconnected".
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 the stopping doesn't work we can get "Completed".
|
@SteveL-MSFT Please update your review. |
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.
Isn't it better to use:
$sb = { 1..10000 | Export-CliXml -Path $testfile -Verbose }This will give syntax coloring and can be analyzed by psscriptanalyzer in vscode
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.
Done.
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.
Another one to change to { ... }
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.
Sorry. Fixed.
4f9a224 to
67b656a
Compare
67b656a to
7507fd7
Compare
SteveL-MSFT
left 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.
The test failures indicates that the pipeline finishes before stop is processed. Perhaps we need to rethink how to make the stop predictable.
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
|
No ideas have I how make it more stable so close. |
PR Summary
Last days the tests often failed due to race condition.
See https://powershell.visualstudio.com/PowerShell/_build/results?buildId=2022&view=logs
Fix is to use test hook (write verbose message at cmdlet start) and Wait-UntilTrue function.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests