Skip to content

Commit 93db6d8

Browse files
committed
test: feature_init: retain debug.log and improve detection
This test sporadically fails due to the Python test missing log lines for reasons that are poorly understood. The problem is made worse by the fact that this test does not retain the log files from iteration to iteration. Change the test to do logline detection in a more robust manner (by using `re.search` on the whole log content) in a way that is comparable to the existing `assert_debug_log` utility, and retain all debug.log content from case to case.
1 parent 24fcf6e commit 93db6d8

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

test/functional/feature_init.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def run_test(self):
4444
def sigterm_node():
4545
node.process.terminate()
4646
node.process.wait()
47-
node.debug_log_path.unlink()
48-
node.debug_log_path.touch()
4947

5048
def check_clean_start():
5149
"""Ensure that node restarts successfully after various interrupts."""
@@ -71,7 +69,7 @@ def check_clean_start():
7169
'net thread start',
7270
'addcon thread start',
7371
'loadblk thread start',
74-
# TODO: reenable - see above TODO
72+
# TODO: re-enable - see above TODO
7573
# 'txindex thread start',
7674
'msghand thread start'
7775
]
@@ -84,39 +82,21 @@ def check_clean_start():
8482
# TODO: add -txindex=1 to fully test index initiatlization.
8583
# extra_args=['-txindex=1'],
8684
)
87-
logfile = open(node.debug_log_path, 'r', encoding='utf8')
88-
89-
MAX_SECS_TO_WAIT = 30
90-
start = time.time()
91-
num_lines = 0
9285

93-
while True:
94-
line = logfile.readline()
95-
if line:
96-
num_lines += 1
97-
98-
if line and terminate_line.lower() in line.lower():
99-
self.log.debug(f"Terminating node after {num_lines} log lines seen")
100-
sigterm_node()
101-
break
102-
103-
if (time.time() - start) > MAX_SECS_TO_WAIT:
104-
raise AssertionError(
105-
f"missed line {terminate_line}; terminating now after {num_lines} lines")
106-
107-
if node.process.poll() is not None:
108-
raise AssertionError(f"node failed to start (line: '{terminate_line}')")
86+
num_total_logs = node.wait_for_debug_log([terminate_line], ignore_case=True)
87+
self.log.debug(f"Terminating node after {num_total_logs} log lines seen")
88+
sigterm_node()
10989

11090
check_clean_start()
111-
num_total_logs = len(node.debug_log_path.read_text().splitlines())
11291
self.stop_node(0)
11392

11493
self.log.info(
11594
f"Terminate at some random point in the init process (max logs: {num_total_logs})")
11695

11796
for _ in range(40):
118-
terminate_after = random.randint(1, num_total_logs)
119-
self.log.debug(f"Starting node and will exit after {terminate_after} lines")
97+
num_logs = len(Path(node.debug_log_path).read_text().splitlines())
98+
additional_lines = random.randint(1, num_total_logs)
99+
self.log.debug(f"Starting node and will exit after {additional_lines} lines")
120100
node.start(
121101
# TODO: add -txindex=1 to fully test index initiatlization.
122102
# extra_args=['-txindex=1'],
@@ -132,7 +112,8 @@ def check_clean_start():
132112
if line:
133113
num_lines += 1
134114

135-
if num_lines >= terminate_after or (time.time() - start) > MAX_SECS_TO_WAIT:
115+
if num_lines >= (num_logs + additional_lines) or \
116+
(time.time() - start) > MAX_SECS_TO_WAIT:
136117
self.log.debug(f"Terminating node after {num_lines} log lines seen")
137118
sigterm_node()
138119
break

0 commit comments

Comments
 (0)