]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109594: Fix concurrent.futures test_timeout() (#110018)
authorVictor Stinner <vstinner@python.org>
Thu, 28 Sep 2023 13:21:15 +0000 (15:21 +0200)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2023 13:21:15 +0000 (15:21 +0200)
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.

Lib/test/test_concurrent_futures/test_wait.py
Misc/NEWS.d/next/Tests/2023-09-28-14-47-14.gh-issue-109594.DB5KPP.rst [new file with mode: 0644]

index 3f64ca173c02f64ff9aa1b37639b508ba1170947..ff486202092c813a00995b66dffd917c4a68b21b 100644 (file)
@@ -112,24 +112,25 @@ class WaitTests:
                               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):
diff --git a/Misc/NEWS.d/next/Tests/2023-09-28-14-47-14.gh-issue-109594.DB5KPP.rst b/Misc/NEWS.d/next/Tests/2023-09-28-14-47-14.gh-issue-109594.DB5KPP.rst
new file mode 100644 (file)
index 0000000..5a4ae2b
--- /dev/null
@@ -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.