Skip to content

Commit

Permalink
pythongh-109594: Fix concurrent.futures test_timeout() (python#110018)
Browse files Browse the repository at this point in the history
Fix test_timeout() of test_concurrent_futures.test_wait. Remove the
future which may or may not complete depending if it takes longer
than the timeout ot not. Keep the second future which does not
complete before wait(). Make also the test faster: 0.5 second instead
of 6 seconds, so remove @support.requires_resource('walltime')
decorator.
  • Loading branch information
vstinner authored Sep 28, 2023
1 parent 0baf726 commit 9be283e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Lib/test/test_concurrent_futures/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,25 @@ def test_all_completed(self):
future2]), finished)
self.assertEqual(set(), pending)

@support.requires_resource('walltime')
def test_timeout(self):
future1 = self.executor.submit(mul, 6, 7)
future2 = self.executor.submit(time.sleep, 6)
short_timeout = 0.050
long_timeout = short_timeout * 10

future = self.executor.submit(time.sleep, long_timeout)

finished, pending = futures.wait(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1, future2],
timeout=5,
future],
timeout=short_timeout,
return_when=futures.ALL_COMPLETED)

self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1]), finished)
self.assertEqual(set([future2]), pending)
SUCCESSFUL_FUTURE]),
finished)
self.assertEqual(set([future]), pending)


class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix test_timeout() of test_concurrent_futures.test_wait. Remove the future
which may or may not complete depending if it takes longer than the timeout
ot not. Keep the second future which does not complete before wait()
timeout. Patch by Victor Stinner.

0 comments on commit 9be283e

Please sign in to comment.