[Python-checkins] Tests call sleeping_retry() with SHORT_TIMEOUT (#93870)
vstinner
webhook-mailer at python.org
Wed Jun 15 12:49:22 EDT 2022
https://github.com/python/cpython/commit/50e0866f8792941d2aea8937c63d1cb37bbc35cf
commit: 50e0866f8792941d2aea8937c63d1cb37bbc35cf
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-06-15T18:49:14+02:00
summary:
Tests call sleeping_retry() with SHORT_TIMEOUT (#93870)
Tests now call busy_retry() and sleeping_retry() with SHORT_TIMEOUT
or LONG_TIMEOUT (of test.support), rather than hardcoded constants.
Add also WAIT_ACTIVE_CHILDREN_TIMEOUT constant to
_test_multiprocessing.
files:
M Lib/test/_test_eintr.py
M Lib/test/_test_multiprocessing.py
M Lib/test/test_asyncore.py
M Lib/test/test_concurrent_futures.py
M Lib/test/test_multiprocessing_main_handling.py
M Lib/test/test_signal.py
diff --git a/Lib/test/_test_eintr.py b/Lib/test/_test_eintr.py
index ca637b2906332..006581f7cc6a9 100644
--- a/Lib/test/_test_eintr.py
+++ b/Lib/test/_test_eintr.py
@@ -497,7 +497,7 @@ def _lock(self, lock_func, lock_name):
with open(os_helper.TESTFN, 'wb') as f:
# synchronize the subprocess
start_time = time.monotonic()
- for _ in support.sleeping_retry(60.0, error=False):
+ for _ in support.sleeping_retry(support.LONG_TIMEOUT, error=False):
try:
lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
lock_func(f, fcntl.LOCK_UN)
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index dca5a19d2ed62..b20bc0b08015d 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -124,6 +124,8 @@ def _resource_unlink(name, rtype):
# BaseManager.shutdown_timeout
SHUTDOWN_TIMEOUT = support.SHORT_TIMEOUT
+WAIT_ACTIVE_CHILDREN_TIMEOUT = 5.0
+
HAVE_GETVALUE = not getattr(_multiprocessing,
'HAVE_BROKEN_SEM_GETVALUE', False)
@@ -5569,8 +5571,9 @@ def wait_proc_exit(self):
# if there are other children too (see #17395).
join_process(self.proc)
+ timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
start_time = time.monotonic()
- for _ in support.sleeping_retry(5.0, error=False):
+ for _ in support.sleeping_retry(timeout, error=False):
if len(multiprocessing.active_children()) <= 1:
break
else:
@@ -5875,8 +5878,9 @@ def tearDownClass(cls):
# only the manager process should be returned by active_children()
# but this can take a bit on slow machines, so wait a few seconds
# if there are other children too (see #17395)
+ timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
start_time = time.monotonic()
- for _ in support.sleeping_retry(5.0, error=False):
+ for _ in support.sleeping_retry(timeout, error=False):
if len(multiprocessing.active_children()) <= 1:
break
else:
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index dd6b3a3648e6b..7d3e2011189a5 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -76,7 +76,7 @@ def capture_server(evt, buf, serv):
pass
else:
n = 200
- for _ in support.busy_retry(3.0, error=False):
+ for _ in support.busy_retry(support.SHORT_TIMEOUT, error=False):
r, w, e = select.select([conn], [], [], 0.1)
if r:
n -= 1
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index c12165366bb25..f50255bd57560 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -258,7 +258,8 @@ def test_initializer(self):
future.result()
# At some point, the executor should break
- for _ in support.sleeping_retry(5, "executor not broken"):
+ for _ in support.sleeping_retry(support.SHORT_TIMEOUT,
+ "executor not broken"):
if self.executor._broken:
break
diff --git a/Lib/test/test_multiprocessing_main_handling.py b/Lib/test/test_multiprocessing_main_handling.py
index 35e9cd64fa6c0..6b30a89316703 100644
--- a/Lib/test/test_multiprocessing_main_handling.py
+++ b/Lib/test/test_multiprocessing_main_handling.py
@@ -62,7 +62,8 @@ def f(x):
pool.map_async(f, [1, 2, 3], callback=results.extend)
# up to 1 min to report the results
- for _ in support.sleeping_retry(60, "Timed out waiting for results"):
+ for _ in support.sleeping_retry(support.LONG_TIMEOUT,
+ "Timed out waiting for results"):
if results:
break
@@ -93,7 +94,8 @@ def f(x):
with Pool(5) as pool:
pool.map_async(int, [1, 4, 9], callback=results.extend)
# up to 1 min to report the results
- for _ in support.sleeping_retry(60, "Timed out waiting for results"):
+ for _ in support.sleeping_retry(support.LONG_TIMEOUT,
+ "Timed out waiting for results"):
if results:
break
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index a1d074a56cf65..2e115f45be472 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -812,7 +812,7 @@ def test_itimer_virtual(self):
signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
signal.setitimer(self.itimer, 0.3, 0.2)
- for _ in support.busy_retry(60.0, error=False):
+ for _ in support.busy_retry(support.LONG_TIMEOUT, error=False):
# use up some virtual time by doing real work
_ = pow(12345, 67890, 10000019)
if signal.getitimer(self.itimer) == (0.0, 0.0):
@@ -833,7 +833,7 @@ def test_itimer_prof(self):
signal.signal(signal.SIGPROF, self.sig_prof)
signal.setitimer(self.itimer, 0.2, 0.2)
- for _ in support.busy_retry(60.0, error=False):
+ for _ in support.busy_retry(support.LONG_TIMEOUT, error=False):
# do some work
_ = pow(12345, 67890, 10000019)
if signal.getitimer(self.itimer) == (0.0, 0.0):
More information about the Python-checkins
mailing list