Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Sep 19, 2018

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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

@JamesWTruher Can you review?

Copy link
Collaborator Author

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...

Copy link
Member

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?

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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

@iSazonov
Copy link
Collaborator Author

Reopen to restart Ci Appveyor.

@iSazonov iSazonov closed this Sep 20, 2018
@iSazonov iSazonov reopened this Sep 20, 2018
@iSazonov
Copy link
Collaborator Author

Reopen to restart Ci Appveyor.

@iSazonov iSazonov closed this Sep 20, 2018
@iSazonov iSazonov reopened this Sep 20, 2018
@TravisEz13
Copy link
Member

@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.

@iSazonov
Copy link
Collaborator Author

@TravisEz13 I sent.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

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?

@iSazonov iSazonov force-pushed the fix-race-condition-in-tests branch from 861e0c2 to dddfaa2 Compare September 25, 2018 04:36
Copy link
Collaborator

@JamesWTruher JamesWTruher left a 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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Collaborator Author

@iSazonov iSazonov Sep 26, 2018

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.)

Copy link
Collaborator

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".

Copy link
Collaborator Author

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".

@iSazonov
Copy link
Collaborator Author

iSazonov commented Oct 1, 2018

@SteveL-MSFT Please update your review.

Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

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 { ... }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry. Fixed.

@iSazonov iSazonov force-pushed the fix-race-condition-in-tests branch from 4f9a224 to 67b656a Compare October 3, 2018 03:08
@iSazonov iSazonov force-pushed the fix-race-condition-in-tests branch from 67b656a to 7507fd7 Compare October 3, 2018 13:22
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.

The test failures indicates that the pipeline finishes before stop is processed. Perhaps we need to rethink how to make the stop predictable.

@stale
Copy link

stale bot commented Nov 2, 2018

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.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Nov 2, 2018
@iSazonov
Copy link
Collaborator Author

iSazonov commented Nov 6, 2018

No ideas have I how make it more stable so close.

@iSazonov iSazonov closed this Nov 6, 2018
@iSazonov iSazonov deleted the fix-race-condition-in-tests branch May 15, 2020 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants