Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | class TestNode(): | ||||
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2): | def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2): | ||||
if unexpected_msgs is None: | if unexpected_msgs is None: | ||||
unexpected_msgs = [] | unexpected_msgs = [] | ||||
time_end = time.time() + timeout | time_end = time.time() + timeout | ||||
debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') | debug_log = os.path.join(self.datadir, 'regtest', 'debug.log') | ||||
with open(debug_log, encoding='utf-8') as dl: | with open(debug_log, encoding='utf-8') as dl: | ||||
dl.seek(0, 2) | dl.seek(0, 2) | ||||
prev_size = dl.tell() | prev_size = dl.tell() | ||||
try: | |||||
yield | yield | ||||
finally: | |||||
while True: | while True: | ||||
found = True | found = True | ||||
with open(debug_log, encoding='utf-8') as dl: | with open(debug_log, encoding='utf-8') as dl: | ||||
dl.seek(prev_size) | dl.seek(prev_size) | ||||
log = dl.read() | log = dl.read() | ||||
print_log = " - " + "\n - ".join(log.splitlines()) | print_log = " - " + "\n - ".join(log.splitlines()) | ||||
for unexpected_msg in unexpected_msgs: | for unexpected_msg in unexpected_msgs: | ||||
if re.search(re.escape(unexpected_msg), | if re.search(re.escape(unexpected_msg), | ||||
log, flags=re.MULTILINE): | log, flags=re.MULTILINE): | ||||
self._raise_assertion_error( | self._raise_assertion_error( | ||||
'Unexpected message "{}" partially matches log:\n\n{}\n\n'.format( | 'Unexpected message "{}" partially matches log:\n\n{}\n\n'.format( | ||||
unexpected_msg, print_log)) | unexpected_msg, print_log)) | ||||
for expected_msg in expected_msgs: | for expected_msg in expected_msgs: | ||||
if re.search(re.escape(expected_msg), log, | if re.search(re.escape(expected_msg), log, | ||||
flags=re.MULTILINE) is None: | flags=re.MULTILINE) is None: | ||||
found = False | found = False | ||||
if found: | if found: | ||||
return | return | ||||
if time.time() >= time_end: | if time.time() >= time_end: | ||||
break | break | ||||
time.sleep(0.05) | time.sleep(0.05) | ||||
self._raise_assertion_error( | self._raise_assertion_error( | ||||
'Expected messages "{}" does not partially match log:\n\n{}\n\n'.format( | 'Expected messages "{}" does not partially match log:\n\n{}\n\n'.format( | ||||
str(expected_msgs), print_log)) | str(expected_msgs), print_log)) | ||||
def assert_start_raises_init_error( | def assert_start_raises_init_error( | ||||
self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs): | self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs): | ||||
"""Attempt to start the node and expect it to raise an error. | """Attempt to start the node and expect it to raise an error. | ||||
extra_args: extra arguments to pass through to bitcoind | extra_args: extra arguments to pass through to bitcoind | ||||
expected_msg: regex that stderr should match when bitcoind fails | expected_msg: regex that stderr should match when bitcoind fails | ||||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |