Skip to content

Commit 091cf8f

Browse files
committed
Avoid hanging in tests if timeout doesn't work.
1 parent 32beb07 commit 091cf8f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

atest/testdata/running/timeouts_with_logging.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88

99

1010
def rf_logger():
11-
while True:
12-
logger.info(MSG)
13-
time.sleep(0) # give time for other threads
11+
_log_a_lot(logger.info)
1412

1513

1614
def python_logging():
17-
while True:
18-
logging.info(MSG)
19-
time.sleep(0) # give time for other threads
15+
_log_a_lot(logging.info)
16+
17+
18+
def _log_a_lot(info):
19+
# Assigning local variables is performance optimization to give as much
20+
# time as as possible for actual logging.
21+
msg = MSG
22+
sleep = time.sleep
23+
current = time.time
24+
end = current() + 1
25+
while current() < end:
26+
info(msg)
27+
sleep(0) # give time for other threads
28+
raise AssertionError('Execution should have been stopped by timeout.')

0 commit comments

Comments
 (0)