]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-128364: Fix flaky `test_timeout` test (gh-130724) (gh-130729)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 1 Mar 2025 16:40:53 +0000 (17:40 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Mar 2025 16:40:53 +0000 (16:40 +0000)
gh-128364: Fix flaky `test_timeout` test (gh-130724)
(cherry picked from commit cfa0b1dc375e63cde28e61a47108c645b0e74834)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Lib/test/test_concurrent_futures/test_wait.py
Lib/test/test_concurrent_futures/util.py

index ff486202092c813a00995b66dffd917c4a68b21b..3527a74a708b20d01cc57f9a9e3a38ed4a2f7efa 100644 (file)
@@ -114,9 +114,8 @@ class WaitTests:
 
     def test_timeout(self):
         short_timeout = 0.050
-        long_timeout = short_timeout * 10
 
-        future = self.executor.submit(time.sleep, long_timeout)
+        future = self.executor.submit(self.event.wait)
 
         finished, pending = futures.wait(
                 [CANCELLED_AND_NOTIFIED_FUTURE,
@@ -132,6 +131,9 @@ class WaitTests:
                          finished)
         self.assertEqual(set([future]), pending)
 
+        # Set the event to allow the future to complete
+        self.event.set()
+
 
 class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase):
 
index fc6030e375fb6b0071fb0dbabab1458dd83a04e1..93ae2459ac52377d2033b7a8e1dc8d89ed5abc8c 100644 (file)
@@ -1,5 +1,6 @@
 import multiprocessing
 import sys
+import threading
 import time
 import unittest
 from concurrent import futures
@@ -46,11 +47,14 @@ class ExecutorMixin:
 
         self.t1 = time.monotonic()
         if hasattr(self, "ctx"):
+            self.manager = multiprocessing.Manager()
+            self.event = self.manager.Event()
             self.executor = self.executor_type(
                 max_workers=self.worker_count,
                 mp_context=self.get_context(),
                 **self.executor_kwargs)
         else:
+            self.event = threading.Event()
             self.executor = self.executor_type(
                 max_workers=self.worker_count,
                 **self.executor_kwargs)
@@ -58,6 +62,9 @@ class ExecutorMixin:
     def tearDown(self):
         self.executor.shutdown(wait=True)
         self.executor = None
+        if hasattr(self, "ctx"):
+            self.manager.shutdown()
+            self.manager = None
 
         dt = time.monotonic() - self.t1
         if support.verbose: