Skip to content

Commit 50e0866

Browse files
authored
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.
1 parent 46e455f commit 50e0866

6 files changed

+16
-9
lines changed

Lib/test/_test_eintr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def _lock(self, lock_func, lock_name):
497497
with open(os_helper.TESTFN, 'wb') as f:
498498
# synchronize the subprocess
499499
start_time = time.monotonic()
500-
for _ in support.sleeping_retry(60.0, error=False):
500+
for _ in support.sleeping_retry(support.LONG_TIMEOUT, error=False):
501501
try:
502502
lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
503503
lock_func(f, fcntl.LOCK_UN)

Lib/test/_test_multiprocessing.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def _resource_unlink(name, rtype):
124124
# BaseManager.shutdown_timeout
125125
SHUTDOWN_TIMEOUT = support.SHORT_TIMEOUT
126126

127+
WAIT_ACTIVE_CHILDREN_TIMEOUT = 5.0
128+
127129
HAVE_GETVALUE = not getattr(_multiprocessing,
128130
'HAVE_BROKEN_SEM_GETVALUE', False)
129131

@@ -5569,8 +5571,9 @@ def wait_proc_exit(self):
55695571
# if there are other children too (see #17395).
55705572
join_process(self.proc)
55715573

5574+
timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
55725575
start_time = time.monotonic()
5573-
for _ in support.sleeping_retry(5.0, error=False):
5576+
for _ in support.sleeping_retry(timeout, error=False):
55745577
if len(multiprocessing.active_children()) <= 1:
55755578
break
55765579
else:
@@ -5875,8 +5878,9 @@ def tearDownClass(cls):
58755878
# only the manager process should be returned by active_children()
58765879
# but this can take a bit on slow machines, so wait a few seconds
58775880
# if there are other children too (see #17395)
5881+
timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
58785882
start_time = time.monotonic()
5879-
for _ in support.sleeping_retry(5.0, error=False):
5883+
for _ in support.sleeping_retry(timeout, error=False):
58805884
if len(multiprocessing.active_children()) <= 1:
58815885
break
58825886
else:

Lib/test/test_asyncore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def capture_server(evt, buf, serv):
7676
pass
7777
else:
7878
n = 200
79-
for _ in support.busy_retry(3.0, error=False):
79+
for _ in support.busy_retry(support.SHORT_TIMEOUT, error=False):
8080
r, w, e = select.select([conn], [], [], 0.1)
8181
if r:
8282
n -= 1

Lib/test/test_concurrent_futures.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ def test_initializer(self):
258258
future.result()
259259

260260
# At some point, the executor should break
261-
for _ in support.sleeping_retry(5, "executor not broken"):
261+
for _ in support.sleeping_retry(support.SHORT_TIMEOUT,
262+
"executor not broken"):
262263
if self.executor._broken:
263264
break
264265

Lib/test/test_multiprocessing_main_handling.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def f(x):
6262
pool.map_async(f, [1, 2, 3], callback=results.extend)
6363
6464
# up to 1 min to report the results
65-
for _ in support.sleeping_retry(60, "Timed out waiting for results"):
65+
for _ in support.sleeping_retry(support.LONG_TIMEOUT,
66+
"Timed out waiting for results"):
6667
if results:
6768
break
6869
@@ -93,7 +94,8 @@ def f(x):
9394
with Pool(5) as pool:
9495
pool.map_async(int, [1, 4, 9], callback=results.extend)
9596
# up to 1 min to report the results
96-
for _ in support.sleeping_retry(60, "Timed out waiting for results"):
97+
for _ in support.sleeping_retry(support.LONG_TIMEOUT,
98+
"Timed out waiting for results"):
9799
if results:
98100
break
99101

Lib/test/test_signal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def test_itimer_virtual(self):
812812
signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
813813
signal.setitimer(self.itimer, 0.3, 0.2)
814814

815-
for _ in support.busy_retry(60.0, error=False):
815+
for _ in support.busy_retry(support.LONG_TIMEOUT, error=False):
816816
# use up some virtual time by doing real work
817817
_ = pow(12345, 67890, 10000019)
818818
if signal.getitimer(self.itimer) == (0.0, 0.0):
@@ -833,7 +833,7 @@ def test_itimer_prof(self):
833833
signal.signal(signal.SIGPROF, self.sig_prof)
834834
signal.setitimer(self.itimer, 0.2, 0.2)
835835

836-
for _ in support.busy_retry(60.0, error=False):
836+
for _ in support.busy_retry(support.LONG_TIMEOUT, error=False):
837837
# do some work
838838
_ = pow(12345, 67890, 10000019)
839839
if signal.getitimer(self.itimer) == (0.0, 0.0):

0 commit comments

Comments
 (0)