Skip to content

Commit 455780b

Browse files
author
MacroFake
committed
Merge bitcoin#25294: test: Fix wait_for_debug_log UnicodeDecodeError
fa74b63 test: Fix wait_for_debug_log UnicodeDecodeError (MacroFake) Pull request description: Fix the intermittent `UnicodeDecodeError` when the debug log is truncated on an (multi-byte) unicode character by treating everything as bytes. Also, remove the `ignore_case` option and the`re.search+re.escape` wrap. All of this is unused and doesn't exist on raw byte strings. Fixes bitcoin#24575 ACKs for top commit: jonatack: ACK fa74b63 brunoerg: ACK fa74b63 Tree-SHA512: c67c9355073e784fa8d9d48b8e79ff0c98f5ae9cd4d704ad12a76d2604733946054bc74b8ab346aa2184db23d740b85c8c13eb892d76cba92e42ebfd73f2f1bf
2 parents 2e079c8 + fa74b63 commit 455780b

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

test/functional/feature_init.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,33 @@ def check_clean_start():
4949
assert_equal(200, node.getblockcount())
5050

5151
lines_to_terminate_after = [
52-
'Validating signatures for all blocks',
53-
'scheduler thread start',
54-
'Starting HTTP server',
55-
'Loading P2P addresses',
56-
'Loading banlist',
57-
'Loading block index',
58-
'Switching active chainstate',
59-
'Checking all blk files are present',
60-
'Loaded best chain:',
61-
'init message: Verifying blocks',
62-
'init message: Starting network threads',
63-
'net thread start',
64-
'addcon thread start',
65-
'loadblk thread start',
66-
'txindex thread start',
67-
'block filter index thread start',
68-
'coinstatsindex thread start',
69-
'msghand thread start',
70-
'net thread start',
71-
'addcon thread start',
52+
b'Validating signatures for all blocks',
53+
b'scheduler thread start',
54+
b'Starting HTTP server',
55+
b'Loading P2P addresses',
56+
b'Loading banlist',
57+
b'Loading block index',
58+
b'Switching active chainstate',
59+
b'Checking all blk files are present',
60+
b'Loaded best chain:',
61+
b'init message: Verifying blocks',
62+
b'init message: Starting network threads',
63+
b'net thread start',
64+
b'addcon thread start',
65+
b'loadblk thread start',
66+
b'txindex thread start',
67+
b'block filter index thread start',
68+
b'coinstatsindex thread start',
69+
b'msghand thread start',
70+
b'net thread start',
71+
b'addcon thread start',
7272
]
7373
if self.is_wallet_compiled():
74-
lines_to_terminate_after.append('Verifying wallet')
74+
lines_to_terminate_after.append(b'Verifying wallet')
7575

7676
for terminate_line in lines_to_terminate_after:
77-
self.log.info(f"Starting node and will exit after line '{terminate_line}'")
78-
with node.wait_for_debug_log([terminate_line], ignore_case=True):
77+
self.log.info(f"Starting node and will exit after line {terminate_line}")
78+
with node.wait_for_debug_log([terminate_line]):
7979
node.start(extra_args=['-txindex=1', '-blockfilterindex=1', '-coinstatsindex=1'])
8080
self.log.debug("Terminating node after terminate line was found")
8181
sigterm_node()

test/functional/test_framework/test_node.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -423,26 +423,25 @@ def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
423423
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
424424

425425
@contextlib.contextmanager
426-
def wait_for_debug_log(self, expected_msgs, timeout=60, ignore_case=False):
426+
def wait_for_debug_log(self, expected_msgs, timeout=60):
427427
"""
428428
Block until we see a particular debug log message fragment or until we exceed the timeout.
429429
Return:
430430
the number of log lines we encountered when matching
431431
"""
432432
time_end = time.time() + timeout * self.timeout_factor
433433
prev_size = self.debug_log_bytes()
434-
re_flags = re.MULTILINE | (re.IGNORECASE if ignore_case else 0)
435434

436435
yield
437436

438437
while True:
439438
found = True
440-
with open(self.debug_log_path, encoding='utf-8') as dl:
439+
with open(self.debug_log_path, "rb") as dl:
441440
dl.seek(prev_size)
442441
log = dl.read()
443442

444443
for expected_msg in expected_msgs:
445-
if re.search(re.escape(expected_msg), log, flags=re_flags) is None:
444+
if expected_msg not in log:
446445
found = False
447446

448447
if found:

0 commit comments

Comments
 (0)