mirror of
https://github.com/python/cpython.git
synced 2025-11-09 10:01:42 +00:00
[3.13] gh-128364: Fix flaky test_concurrent_futures.test_wait tests (gh-130742) (#130922)
Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
(cherry picked from commit c4d37eefb7)
This commit is contained in:
parent
e285232c76
commit
0c088e4442
2 changed files with 116 additions and 58 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import multiprocessing
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from concurrent import futures
|
||||
|
|
@ -50,14 +51,19 @@ def setUp(self):
|
|||
max_workers=self.worker_count,
|
||||
mp_context=self.get_context(),
|
||||
**self.executor_kwargs)
|
||||
self.manager = self.get_context().Manager()
|
||||
else:
|
||||
self.executor = self.executor_type(
|
||||
max_workers=self.worker_count,
|
||||
**self.executor_kwargs)
|
||||
self.manager = None
|
||||
|
||||
def tearDown(self):
|
||||
self.executor.shutdown(wait=True)
|
||||
self.executor = None
|
||||
if self.manager is not None:
|
||||
self.manager.shutdown()
|
||||
self.manager = None
|
||||
|
||||
dt = time.monotonic() - self.t1
|
||||
if support.verbose:
|
||||
|
|
@ -73,6 +79,9 @@ def get_context(self):
|
|||
class ThreadPoolMixin(ExecutorMixin):
|
||||
executor_type = futures.ThreadPoolExecutor
|
||||
|
||||
def create_event(self):
|
||||
return threading.Event()
|
||||
|
||||
|
||||
class ProcessPoolForkMixin(ExecutorMixin):
|
||||
executor_type = futures.ProcessPoolExecutor
|
||||
|
|
@ -89,6 +98,9 @@ def get_context(self):
|
|||
self.skipTest("TSAN doesn't support threads after fork")
|
||||
return super().get_context()
|
||||
|
||||
def create_event(self):
|
||||
return self.manager.Event()
|
||||
|
||||
|
||||
class ProcessPoolSpawnMixin(ExecutorMixin):
|
||||
executor_type = futures.ProcessPoolExecutor
|
||||
|
|
@ -101,6 +113,9 @@ def get_context(self):
|
|||
self.skipTest("ProcessPoolExecutor unavailable on this system")
|
||||
return super().get_context()
|
||||
|
||||
def create_event(self):
|
||||
return self.manager.Event()
|
||||
|
||||
|
||||
class ProcessPoolForkserverMixin(ExecutorMixin):
|
||||
executor_type = futures.ProcessPoolExecutor
|
||||
|
|
@ -117,6 +132,9 @@ def get_context(self):
|
|||
self.skipTest("TSAN doesn't support threads after fork")
|
||||
return super().get_context()
|
||||
|
||||
def create_event(self):
|
||||
return self.manager.Event()
|
||||
|
||||
|
||||
def create_executor_tests(remote_globals, mixin, bases=(BaseTestCase,),
|
||||
executor_mixins=(ThreadPoolMixin,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue