Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 312 Lines • ▼ Show 20 Lines | def is_node_stopped(self): | ||||
self.rpc = None | self.rpc = None | ||||
self.log.debug("Node stopped") | self.log.debug("Node stopped") | ||||
return True | return True | ||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | ||||
wait_until(self.is_node_stopped, timeout=timeout) | wait_until(self.is_node_stopped, timeout=timeout) | ||||
@contextlib.contextmanager | @contextlib.contextmanager | ||||
def assert_debug_log(self, expected_msgs): | def assert_debug_log(self, expected_msgs, timeout=2): | ||||
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: | try: | ||||
yield | yield | ||||
finally: | finally: | ||||
while 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 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 | |||||
if found: | |||||
return | |||||
if time.time() >= time_end: | |||||
break | |||||
time.sleep(0.05) | |||||
self._raise_assertion_error( | self._raise_assertion_error( | ||||
'Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) | 'Expected messages "{}" does not partially match log:\n\n{}\n\n'.format( | ||||
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 |