Skip to content

Commit

Permalink
Fix a race condition in a multithreaded test (#1798)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdickinson authored May 21, 2024
1 parent d61299f commit bc12dc4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions traits/tests/test_ui_notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ def test_notification_from_separate_thread_failure_case(self):
# Given no registered ui handler
self.enterContext(clear_ui_handler())

# When we set obj.foo to 3 on a separate thread.
# When we set obj.foo to 3 on a separate thread, and wait for
# that thread to complete.
background_thread = threading.Thread(target=self.modify_obj)
background_thread.start()
self.addCleanup(background_thread.join)
background_thread.join()

# Then no notification is processed ...
self.assertEqual(self.notifications, [])
Expand Down

0 comments on commit bc12dc4

Please sign in to comment.