Skip to content

Commit 9be283e

Browse files
authored
gh-109594: Fix concurrent.futures test_timeout() (#110018)
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.
1 parent 0baf726 commit 9be283e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Lib/test/test_concurrent_futures/test_wait.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,25 @@ def test_all_completed(self):
112112
future2]), finished)
113113
self.assertEqual(set(), pending)
114114

115-
@support.requires_resource('walltime')
116115
def test_timeout(self):
117-
future1 = self.executor.submit(mul, 6, 7)
118-
future2 = self.executor.submit(time.sleep, 6)
116+
short_timeout = 0.050
117+
long_timeout = short_timeout * 10
118+
119+
future = self.executor.submit(time.sleep, long_timeout)
119120

120121
finished, pending = futures.wait(
121122
[CANCELLED_AND_NOTIFIED_FUTURE,
122123
EXCEPTION_FUTURE,
123124
SUCCESSFUL_FUTURE,
124-
future1, future2],
125-
timeout=5,
125+
future],
126+
timeout=short_timeout,
126127
return_when=futures.ALL_COMPLETED)
127128

128129
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
129130
EXCEPTION_FUTURE,
130-
SUCCESSFUL_FUTURE,
131-
future1]), finished)
132-
self.assertEqual(set([future2]), pending)
131+
SUCCESSFUL_FUTURE]),
132+
finished)
133+
self.assertEqual(set([future]), pending)
133134

134135

135136
class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix test_timeout() of test_concurrent_futures.test_wait. Remove the future
2+
which may or may not complete depending if it takes longer than the timeout
3+
ot not. Keep the second future which does not complete before wait()
4+
timeout. Patch by Victor Stinner.

0 commit comments

Comments
 (0)