diff options
author | teor <teor@torproject.org> | 2018-10-06 16:10:37 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-11-02 13:14:23 -0400 |
commit | a02d6c560d8b574003b4c34907c1656f8c57e857 (patch) | |
tree | 3dceaa94369629cb7ccf20fd2fcf1cca262aafaa /src/test/test_rebind.py | |
parent | cd674a10ad989120e7b8060ebe6d8f2626bf4a65 (diff) | |
download | tor-a02d6c560d8b574003b4c34907c1656f8c57e857.tar.gz tor-a02d6c560d8b574003b4c34907c1656f8c57e857.zip |
Make test_rebind.py timeout when waiting for a log message
Closes #27968.
Diffstat (limited to 'src/test/test_rebind.py')
-rw-r--r-- | src/test/test_rebind.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/test/test_rebind.py b/src/test/test_rebind.py index 3600dd5d58..5e671de308 100644 --- a/src/test/test_rebind.py +++ b/src/test/test_rebind.py @@ -8,6 +8,10 @@ import time import random import errno +LOG_TIMEOUT = 60.0 +LOG_WAIT = 0.1 +LOG_CHECK_LIMIT = LOG_TIMEOUT / LOG_WAIT + def fail(msg): print('FAIL') sys.exit(msg) @@ -20,10 +24,19 @@ def try_connecting_to_socksport(): socks_socket.close() def wait_for_log(s): - while True: + log_checked = 0 + while log_checked < LOG_CHECK_LIMIT: l = tor_process.stdout.readline() - if s in l.decode('utf8'): + l = l.decode('utf8') + if s in l: return + print('Tor logged: "{}", waiting for "{}"'.format(l.strip(), s)) + # readline() returns a blank string when there is no output + # avoid busy-waiting + if len(s) == 0: + time.sleep(LOG_WAIT) + log_checked += 1 + fail('Could not find "{}" in logs after {} seconds'.format(s, LOG_TIMEOUT)) def pick_random_port(): port = 0 |