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

Fix race condition in unit test #2108

Merged
merged 1 commit into from
Dec 11, 2020
Merged

Fix race condition in unit test #2108

merged 1 commit into from
Dec 11, 2020

Conversation

narrieta
Copy link
Member

There was a race condition between the child process creating its file and the callback being invoked. Fixed by waiting for the callbacks explicitly.

@staticmethod
def _wait_for(predicate):
start_time = datetime.datetime.now()
while RunCommandTestCase._to_seconds(datetime.datetime.now() - start_time) < 30:
Copy link
Contributor

Choose a reason for hiding this comment

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

So this one test could take up to 30 seconds? Any reason for waiting that long?
Granted, this should only happen if the threads were unable to start for some reason, which is not a normal case.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the test takes 0.05-0,0.08 s (my local machine). 30 s is the timeout if things go wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I was wondering if that timeout could be shorter so we fail faster, but I realized this probably won't happen often.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I think I misunderstood your point. 30 s is probably too generous. I am trying to avoid the test being noisy if, for example, one is running the unit test in a laptop while using a chat app that is taking most of the cpu.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a bad chat app 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

And probably we should add a verification to the entire suite to let us know if the run takes more than some given time. A bad mock, a regression in prod/test code may go unnoticed until somebody stumbles into a slow test run and realizes something is not correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can look into the Github Actions docs; I feel like this sort of thing should be easy to automate as a separate, not required job.

@narrieta narrieta merged commit 0d7cee8 into Azure:develop Dec 11, 2020
@narrieta narrieta deleted the ut branch December 11, 2020 22:09
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.

4 participants