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 a race condition in a multithreaded test #1798

Merged
merged 1 commit into from
May 21, 2024

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented May 21, 2024

This PR fixes an obvious race condition in a test - we're firing off an action in a background thread, but not waiting for that background thread to complete before checking for the side-effects that we're expecting.

This caused a CI failure in a recent Windows run: https://github.com/enthought/traits/actions/runs/9164818354/job/25196928783?pr=1797

@mdickinson mdickinson requested a review from flongford May 21, 2024 08:27
@mdickinson
Copy link
Member Author

@flongford An easy one for you ...

background_thread = threading.Thread(target=self.modify_obj)
background_thread.start()
self.addCleanup(background_thread.join)
background_thread.join()

Choose a reason for hiding this comment

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

We're invoking the same self.addCleanup command in test_notification_from_separate_thread (line 184) - is it appropriate for this test case or should it be changed also?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine for that test case, because we're explicitly waiting for the notification to arrive with an await.

Choose a reason for hiding this comment

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

Ah yes, I see the difference between the two test cases - thanks for clarifying

Copy link

@flongford flongford left a comment

Choose a reason for hiding this comment

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

LGTM!

@mdickinson
Copy link
Member Author

Thanks for review! Merging.

@mdickinson mdickinson merged commit bc12dc4 into main May 21, 2024
29 checks passed
@mdickinson mdickinson deleted the fix/test-race-condition branch May 21, 2024 10:00
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.

2 participants