mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Make test_rebind.py timeout when waiting for a log message
Closes #27968.
This commit is contained in:
parent
cd674a10ad
commit
a02d6c560d
@ -8,6 +8,10 @@ import time
|
|||||||
import random
|
import random
|
||||||
import errno
|
import errno
|
||||||
|
|
||||||
|
LOG_TIMEOUT = 60.0
|
||||||
|
LOG_WAIT = 0.1
|
||||||
|
LOG_CHECK_LIMIT = LOG_TIMEOUT / LOG_WAIT
|
||||||
|
|
||||||
def fail(msg):
|
def fail(msg):
|
||||||
print('FAIL')
|
print('FAIL')
|
||||||
sys.exit(msg)
|
sys.exit(msg)
|
||||||
@ -20,10 +24,19 @@ def try_connecting_to_socksport():
|
|||||||
socks_socket.close()
|
socks_socket.close()
|
||||||
|
|
||||||
def wait_for_log(s):
|
def wait_for_log(s):
|
||||||
while True:
|
log_checked = 0
|
||||||
|
while log_checked < LOG_CHECK_LIMIT:
|
||||||
l = tor_process.stdout.readline()
|
l = tor_process.stdout.readline()
|
||||||
if s in l.decode('utf8'):
|
l = l.decode('utf8')
|
||||||
|
if s in l:
|
||||||
return
|
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():
|
def pick_random_port():
|
||||||
port = 0
|
port = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user