Skip to content

Commit ff3cadd

Browse files
[3.11] gh-109594: Fix concurrent.futures test_timeout() (GH-110018) (#110022)
gh-109594: Fix concurrent.futures test_timeout() (GH-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. (cherry picked from commit 9be283e) Co-authored-by: Victor Stinner <[email protected]>
1 parent 82dea84 commit ff3cadd

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Lib/test/test_concurrent_futures/test_wait.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,24 @@ def test_all_completed(self):
111111
self.assertEqual(set(), pending)
112112

113113
def test_timeout(self):
114-
future1 = self.executor.submit(mul, 6, 7)
115-
future2 = self.executor.submit(time.sleep, 6)
114+
short_timeout = 0.050
115+
long_timeout = short_timeout * 10
116+
117+
future = self.executor.submit(time.sleep, long_timeout)
116118

117119
finished, pending = futures.wait(
118120
[CANCELLED_AND_NOTIFIED_FUTURE,
119121
EXCEPTION_FUTURE,
120122
SUCCESSFUL_FUTURE,
121-
future1, future2],
122-
timeout=5,
123+
future],
124+
timeout=short_timeout,
123125
return_when=futures.ALL_COMPLETED)
124126

125127
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
126128
EXCEPTION_FUTURE,
127-
SUCCESSFUL_FUTURE,
128-
future1]), finished)
129-
self.assertEqual(set([future2]), pending)
129+
SUCCESSFUL_FUTURE]),
130+
finished)
131+
self.assertEqual(set([future]), pending)
130132

131133

132134
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)