mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
46e455f21c
commit
50e0866f87
|
@ -497,7 +497,7 @@ class FNTLEINTRTest(EINTRBaseTest):
|
||||||
with open(os_helper.TESTFN, 'wb') as f:
|
with open(os_helper.TESTFN, 'wb') as f:
|
||||||
# synchronize the subprocess
|
# synchronize the subprocess
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
for _ in support.sleeping_retry(60.0, error=False):
|
for _ in support.sleeping_retry(support.LONG_TIMEOUT, error=False):
|
||||||
try:
|
try:
|
||||||
lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
lock_func(f, fcntl.LOCK_UN)
|
lock_func(f, fcntl.LOCK_UN)
|
||||||
|
|
|
@ -124,6 +124,8 @@ else:
|
||||||
# BaseManager.shutdown_timeout
|
# BaseManager.shutdown_timeout
|
||||||
SHUTDOWN_TIMEOUT = support.SHORT_TIMEOUT
|
SHUTDOWN_TIMEOUT = support.SHORT_TIMEOUT
|
||||||
|
|
||||||
|
WAIT_ACTIVE_CHILDREN_TIMEOUT = 5.0
|
||||||
|
|
||||||
HAVE_GETVALUE = not getattr(_multiprocessing,
|
HAVE_GETVALUE = not getattr(_multiprocessing,
|
||||||
'HAVE_BROKEN_SEM_GETVALUE', False)
|
'HAVE_BROKEN_SEM_GETVALUE', False)
|
||||||
|
|
||||||
|
@ -5569,8 +5571,9 @@ class TestSyncManagerTypes(unittest.TestCase):
|
||||||
# if there are other children too (see #17395).
|
# if there are other children too (see #17395).
|
||||||
join_process(self.proc)
|
join_process(self.proc)
|
||||||
|
|
||||||
|
timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
|
||||||
start_time = time.monotonic()
|
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:
|
if len(multiprocessing.active_children()) <= 1:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -5875,8 +5878,9 @@ class ManagerMixin(BaseMixin):
|
||||||
# only the manager process should be returned by active_children()
|
# only the manager process should be returned by active_children()
|
||||||
# but this can take a bit on slow machines, so wait a few seconds
|
# but this can take a bit on slow machines, so wait a few seconds
|
||||||
# if there are other children too (see #17395)
|
# if there are other children too (see #17395)
|
||||||
|
timeout = WAIT_ACTIVE_CHILDREN_TIMEOUT
|
||||||
start_time = time.monotonic()
|
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:
|
if len(multiprocessing.active_children()) <= 1:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -76,7 +76,7 @@ def capture_server(evt, buf, serv):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
n = 200
|
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)
|
r, w, e = select.select([conn], [], [], 0.1)
|
||||||
if r:
|
if r:
|
||||||
n -= 1
|
n -= 1
|
||||||
|
|
|
@ -258,7 +258,8 @@ class FailingInitializerMixin(ExecutorMixin):
|
||||||
future.result()
|
future.result()
|
||||||
|
|
||||||
# At some point, the executor should break
|
# 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:
|
if self.executor._broken:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,8 @@ if __name__ == '__main__':
|
||||||
pool.map_async(f, [1, 2, 3], callback=results.extend)
|
pool.map_async(f, [1, 2, 3], callback=results.extend)
|
||||||
|
|
||||||
# up to 1 min to report the results
|
# 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:
|
if results:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -93,7 +94,8 @@ results = []
|
||||||
with Pool(5) as pool:
|
with Pool(5) as pool:
|
||||||
pool.map_async(int, [1, 4, 9], callback=results.extend)
|
pool.map_async(int, [1, 4, 9], callback=results.extend)
|
||||||
# up to 1 min to report the results
|
# 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:
|
if results:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -812,7 +812,7 @@ class ItimerTest(unittest.TestCase):
|
||||||
signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
|
signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
|
||||||
signal.setitimer(self.itimer, 0.3, 0.2)
|
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
|
# use up some virtual time by doing real work
|
||||||
_ = pow(12345, 67890, 10000019)
|
_ = pow(12345, 67890, 10000019)
|
||||||
if signal.getitimer(self.itimer) == (0.0, 0.0):
|
if signal.getitimer(self.itimer) == (0.0, 0.0):
|
||||||
|
@ -833,7 +833,7 @@ class ItimerTest(unittest.TestCase):
|
||||||
signal.signal(signal.SIGPROF, self.sig_prof)
|
signal.signal(signal.SIGPROF, self.sig_prof)
|
||||||
signal.setitimer(self.itimer, 0.2, 0.2)
|
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
|
# do some work
|
||||||
_ = pow(12345, 67890, 10000019)
|
_ = pow(12345, 67890, 10000019)
|
||||||
if signal.getitimer(self.itimer) == (0.0, 0.0):
|
if signal.getitimer(self.itimer) == (0.0, 0.0):
|
||||||
|
|
Loading…
Reference in New Issue