Skip to content

Commit

Permalink
Call busy_retry() and sleeping_retry() with error=True
Browse files Browse the repository at this point in the history
Tests no longer call busy_retry() and sleeping_retry() with
error=False: raise an exception if the loop times out.
  • Loading branch information
vstinner committed Jun 15, 2022
1 parent 50e0866 commit 3853ba8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Lib/test/fork_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_wait(self):
self.threads.append(thread)

# busy-loop to wait for threads
for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
if len(self.alive) >= NUM_THREADS:
break

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def capture_server(evt, buf, serv):
pass
else:
n = 200
for _ in support.busy_retry(support.SHORT_TIMEOUT, error=False):
for _ in support.busy_retry(support.SHORT_TIMEOUT):
r, w, e = select.select([conn], [], [], 0.1)
if r:
n -= 1
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3613,11 +3613,10 @@ def do_queuehandler_configuration(self, qspec, lspec):
logging.warning('baz')

# Need to let the listener thread finish its work
while support.sleeping_retry(support.LONG_TIMEOUT, error=False):
while support.sleeping_retry(support.LONG_TIMEOUT,
"queue not empty"):
if qh.listener.queue.empty():
break
else:
self.fail("queue not empty")

with open(fn, encoding='utf-8') as f:
data = f.read().splitlines()
Expand Down
14 changes: 3 additions & 11 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,12 @@ 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(support.LONG_TIMEOUT, error=False):
for _ in support.busy_retry(support.LONG_TIMEOUT):
# use up some virtual time by doing real work
_ = pow(12345, 67890, 10000019)
if signal.getitimer(self.itimer) == (0.0, 0.0):
# sig_vtalrm handler stopped this itimer
break
else:
# bpo-8424
self.skipTest("timeout: likely cause: machine too slow or load too "
"high")

# virtual itimer should be (0.0, 0.0) now
self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
Expand All @@ -833,16 +829,12 @@ 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(support.LONG_TIMEOUT, error=False):
for _ in support.busy_retry(support.LONG_TIMEOUT):
# do some work
_ = pow(12345, 67890, 10000019)
if signal.getitimer(self.itimer) == (0.0, 0.0):
# sig_prof handler stopped this itimer
break
else:
# bpo-8424
self.skipTest("timeout: likely cause: machine too slow or load too "
"high")

# profiling itimer should be (0.0, 0.0) now
self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
Expand Down Expand Up @@ -1317,7 +1309,7 @@ def handler(signum, frame):

expected_sigs += 2
# Wait for handlers to run to avoid signal coalescing
for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
if len(sigs) >= expected_sigs:
break

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_wait3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def wait_impl(self, cpid, *, exitcode):
# This many iterations can be required, since some previously run
# tests (e.g. test_ctypes) could have spawned a lot of children
# very quickly.
for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
# wait3() shouldn't hang, but some of the buildbots seem to hang
# in the forking tests. This is an attempt to fix the problem.
spid, status, rusage = os.wait3(os.WNOHANG)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_wait4.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def wait_impl(self, cpid, *, exitcode):
# Issue #11185: wait4 is broken on AIX and will always return 0
# with WNOHANG.
option = 0
for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
# wait4() shouldn't hang, but some of the buildbots seem to hang
# in the forking tests. This is an attempt to fix the problem.
spid, status, rusage = os.wait4(cpid, option)
Expand Down

0 comments on commit 3853ba8

Please sign in to comment.