merge bitcoin#25294: Fix wait_for_debug_log UnicodeDecodeError

This commit is contained in:
Kittywhiskers Van Gogh 2024-10-05 07:51:18 +00:00
parent 445047db63
commit ecb16808a6
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 26 additions and 27 deletions

View File

@ -49,33 +49,33 @@ class InitStressTest(BitcoinTestFramework):
assert_equal(200, node.getblockcount()) assert_equal(200, node.getblockcount())
lines_to_terminate_after = [ lines_to_terminate_after = [
'Validating signatures for all blocks', b'Validating signatures for all blocks',
'scheduler thread start', b'scheduler thread start',
'Starting HTTP server', b'Starting HTTP server',
'Loading P2P addresses', b'Loading P2P addresses',
'Loading banlist', b'Loading banlist',
'Loading block index', b'Loading block index',
'Switching active chainstate', b'Switching active chainstate',
'Checking all blk files are present', b'Checking all blk files are present',
'Loaded best chain:', b'Loaded best chain:',
'init message: Verifying blocks', b'init message: Verifying blocks',
'init message: Starting network threads', b'init message: Starting network threads',
'net thread start', b'net thread start',
'addcon thread start', b'addcon thread start',
'loadblk thread start', b'loadblk thread start',
'txindex thread start', b'txindex thread start',
'block filter index thread start', b'block filter index thread start',
'coinstatsindex thread start', b'coinstatsindex thread start',
'msghand thread start', b'msghand thread start',
'net thread start', b'net thread start',
'addcon thread start', b'addcon thread start',
] ]
if self.is_wallet_compiled(): if self.is_wallet_compiled():
lines_to_terminate_after.append('Verifying wallet') lines_to_terminate_after.append(b'Verifying wallet')
for terminate_line in lines_to_terminate_after: for terminate_line in lines_to_terminate_after:
self.log.info(f"Starting node and will exit after line '{terminate_line}'") self.log.info(f"Starting node and will exit after line {terminate_line}")
with node.wait_for_debug_log([terminate_line], ignore_case=True): with node.wait_for_debug_log([terminate_line]):
node.start(extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1']) node.start(extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1'])
self.log.debug("Terminating node after terminate line was found") self.log.debug("Terminating node after terminate line was found")
sigterm_node() sigterm_node()

View File

@ -443,7 +443,7 @@ class TestNode():
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log)) self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
@contextlib.contextmanager @contextlib.contextmanager
def wait_for_debug_log(self, expected_msgs, timeout=60, ignore_case=False): def wait_for_debug_log(self, expected_msgs, timeout=60):
""" """
Block until we see a particular debug log message fragment or until we exceed the timeout. Block until we see a particular debug log message fragment or until we exceed the timeout.
Return: Return:
@ -451,18 +451,17 @@ class TestNode():
""" """
time_end = time.time() + timeout * self.timeout_factor time_end = time.time() + timeout * self.timeout_factor
prev_size = self.debug_log_bytes() prev_size = self.debug_log_bytes()
re_flags = re.MULTILINE | (re.IGNORECASE if ignore_case else 0)
yield yield
while True: while True:
found = True found = True
with open(self.debug_log_path, encoding='utf-8') as dl: with open(self.debug_log_path, "rb") as dl:
dl.seek(prev_size) dl.seek(prev_size)
log = dl.read() log = dl.read()
for expected_msg in expected_msgs: for expected_msg in expected_msgs:
if re.search(re.escape(expected_msg), log, flags=re_flags) is None: if expected_msg not in log:
found = False found = False
if found: if found: