-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-128364: Fix flaky test_concurrent_futures.test_wait
tests
#130742
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
gh-128364: Fix flaky test_concurrent_futures.test_wait
tests
#130742
Conversation
Use events instead of relying on `time.sleep()`. The tests are also now about four times faster.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
event = self.create_event() | ||
future1 = self.executor.submit(event.wait) |
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.
Not sure if it could be more helpful, but what about using self.addCleanup(event.set)
and self.addCleanup(future1.result)
here?
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.
Cleanup functions are called too late. They run after tearDown()
where we shutdown the executor and manager.
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.
Oh right..
@@ -50,14 +51,19 @@ def setUp(self): | |||
max_workers=self.worker_count, | |||
mp_context=self.get_context(), | |||
**self.executor_kwargs) | |||
self.manager = multiprocessing.Manager() |
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.
Why using multiprocessing.Manager()
and not self.get_context().Manager()
actually?
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 switched to self.get_context().Manager()
.
@@ -42,8 +42,12 @@ def test_first_completed(self): | |||
self.assertEqual(set([future1]), done) | |||
self.assertEqual(set([CANCELLED_FUTURE, future2]), not_done) | |||
|
|||
event.set() |
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.
Use maybe try/finally to unblock the task on test failure? Same remark for other tests.
@@ -67,9 +84,14 @@ def test_first_exception(self): | |||
self.assertEqual(set([future1, future2]), finished) | |||
self.assertEqual(set([future3]), pending) | |||
|
|||
t.join() |
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.
Use maybe threading_helper.join_thread(t)
(from test.support.threading_helper) to not wait forever if something goes wrong.
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.
LGTM. Thanks for the update.
!buildbot iOS |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 0a94b54 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F130742%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @colesbury, I could not cleanly backport this to
|
… tests (pythongh-130742) Use events instead of relying on `time.sleep()`. The tests are also now about four times faster. (cherry picked from commit c4d37ee) Co-authored-by: Sam Gross <[email protected]>
GH-130922 is a backport of this pull request to the 3.13 branch. |
…gh-130742) (#130922) Use events instead of relying on `time.sleep()`. The tests are also now about four times faster. (cherry picked from commit c4d37ee)
|
…ythongh-130742) Use events instead of relying on `time.sleep()`. The tests are also now about four times faster.
Use events instead of relying on
time.sleep()
. The tests are also now about four times faster.test_concurrent_futures.test_wait.ThreadPoolWaitTests.test_timeout
flakes frequently on free-threaded Windows x64 #128364