-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-100522 Add a test for 'futures.as_completed' timing out with a non-zero timeout value #100523
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -711,7 +711,6 @@ def future_func(): | |
|
||
|
||
class AsCompletedTests: | ||
# TODO([email protected]): Should have a test with a non-zero timeout. | ||
def test_no_timeout(self): | ||
future1 = self.executor.submit(mul, 2, 21) | ||
future2 = self.executor.submit(mul, 7, 6) | ||
|
@@ -728,24 +727,29 @@ def test_no_timeout(self): | |
future1, future2]), | ||
completed) | ||
|
||
def test_zero_timeout(self): | ||
future1 = self.executor.submit(time.sleep, 2) | ||
completed_futures = set() | ||
try: | ||
for future in futures.as_completed( | ||
[CANCELLED_AND_NOTIFIED_FUTURE, | ||
EXCEPTION_FUTURE, | ||
SUCCESSFUL_FUTURE, | ||
future1], | ||
timeout=0): | ||
completed_futures.add(future) | ||
except futures.TimeoutError: | ||
pass | ||
def test_future_times_out(self): | ||
"""Test ``futures.as_completed`` timing out before | ||
completing it's final future.""" | ||
already_completed = {CANCELLED_AND_NOTIFIED_FUTURE, | ||
EXCEPTION_FUTURE, | ||
SUCCESSFUL_FUTURE} | ||
|
||
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE, | ||
EXCEPTION_FUTURE, | ||
SUCCESSFUL_FUTURE]), | ||
completed_futures) | ||
for timeout in (0, 0.01): | ||
with self.subTest(timeout): | ||
|
||
future = self.executor.submit(time.sleep, 0.1) | ||
completed_futures = set() | ||
try: | ||
for f in futures.as_completed( | ||
already_completed | {future}, | ||
timeout | ||
): | ||
completed_futures.add(f) | ||
except futures.TimeoutError: | ||
pass | ||
|
||
# Check that ``future`` wasn't completed. | ||
self.assertEqual(completed_futures, already_completed) | ||
|
||
def test_duplicate_futures(self): | ||
# Issue 20367. Duplicate futures should not raise exceptions or give | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.