@@ -44,14 +44,9 @@ def run_test(self):
44
44
def sigterm_node ():
45
45
node .process .terminate ()
46
46
node .process .wait ()
47
- node .debug_log_path .unlink ()
48
- node .debug_log_path .touch ()
49
47
50
48
def check_clean_start ():
51
49
"""Ensure that node restarts successfully after various interrupts."""
52
- # TODO: add -txindex=1 to fully test index initiatlization.
53
- # See https://github.com/bitcoin/bitcoin/pull/23289#discussion_r735159180 for
54
- # a discussion of the related bug.
55
50
node .start ()
56
51
node .wait_for_rpc_connection ()
57
52
assert_equal (200 , node .getblockcount ())
@@ -71,56 +66,33 @@ def check_clean_start():
71
66
'net thread start' ,
72
67
'addcon thread start' ,
73
68
'loadblk thread start' ,
74
- # TODO: reenable - see above TODO
75
- # 'txindex thread start',
76
- 'msghand thread start'
69
+ 'txindex thread start' ,
70
+ 'msghand thread start' ,
71
+ 'net thread start' ,
72
+ 'addcon thread start' ,
77
73
]
78
74
if self .is_wallet_compiled ():
79
75
lines_to_terminate_after .append ('Verifying wallet' )
80
76
81
77
for terminate_line in lines_to_terminate_after :
82
78
self .log .info (f"Starting node and will exit after line '{ terminate_line } '" )
83
- node .start (
84
- # TODO: add -txindex=1 to fully test index initiatlization.
85
- # extra_args=['-txindex=1'],
86
- )
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
92
-
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" )
79
+ node .start (extra_args = ['-txindex=1' ])
106
80
107
- if node .process .poll () is not None :
108
- raise AssertionError (f"node failed to start (line: '{ terminate_line } ')" )
81
+ num_total_logs = node .wait_for_debug_log ([terminate_line ], ignore_case = True )
82
+ self .log .debug (f"Terminating node after { num_total_logs } log lines seen" )
83
+ sigterm_node ()
109
84
110
85
check_clean_start ()
111
- num_total_logs = len (node .debug_log_path .read_text ().splitlines ())
112
86
self .stop_node (0 )
113
87
114
88
self .log .info (
115
89
f"Terminate at some random point in the init process (max logs: { num_total_logs } )" )
116
90
117
91
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" )
120
- node .start (
121
- # TODO: add -txindex=1 to fully test index initiatlization.
122
- # extra_args=['-txindex=1'],
123
- )
92
+ num_logs = len (Path (node .debug_log_path ).read_text ().splitlines ())
93
+ additional_lines = random .randint (1 , num_total_logs )
94
+ self .log .debug (f"Starting node and will exit after { additional_lines } lines" )
95
+ node .start (extra_args = ['-txindex=1' ])
124
96
logfile = open (node .debug_log_path , 'r' , encoding = 'utf8' )
125
97
126
98
MAX_SECS_TO_WAIT = 10
@@ -132,7 +104,8 @@ def check_clean_start():
132
104
if line :
133
105
num_lines += 1
134
106
135
- if num_lines >= terminate_after or (time .time () - start ) > MAX_SECS_TO_WAIT :
107
+ if num_lines >= (num_logs + additional_lines ) or \
108
+ (time .time () - start ) > MAX_SECS_TO_WAIT :
136
109
self .log .debug (f"Terminating node after { num_lines } log lines seen" )
137
110
sigterm_node ()
138
111
break
@@ -152,11 +125,12 @@ def check_clean_start():
152
125
}
153
126
154
127
for file_patt , err_fragment in files_to_disturb .items ():
155
- target_file = list (node .chain_path .glob (file_patt ))[ 0 ]
128
+ target_files = list (node .chain_path .glob (file_patt ))
156
129
157
- self .log .info (f"Tweaking file to ensure failure { target_file } " )
158
- bak_path = str (target_file ) + ".bak"
159
- target_file .rename (bak_path )
130
+ for target_file in target_files :
131
+ self .log .info (f"Tweaking file to ensure failure { target_file } " )
132
+ bak_path = str (target_file ) + ".bak"
133
+ target_file .rename (bak_path )
160
134
161
135
# TODO: at some point, we should test perturbing the files instead of removing
162
136
# them, e.g.
@@ -170,14 +144,16 @@ def check_clean_start():
170
144
# investigate doing this later.
171
145
172
146
node .assert_start_raises_init_error (
173
- # TODO: add -txindex=1 to fully test index initiatlization.
174
- # extra_args=['-txindex=1'],
147
+ extra_args = ['-txindex=1' ],
175
148
expected_msg = err_fragment ,
176
149
match = ErrorMatch .PARTIAL_REGEX ,
177
150
)
178
151
179
- self .log .info (f"Restoring file from { bak_path } and restarting" )
180
- Path (bak_path ).rename (target_file )
152
+ for target_file in target_files :
153
+ bak_path = str (target_file ) + ".bak"
154
+ self .log .debug (f"Restoring file from { bak_path } and restarting" )
155
+ Path (bak_path ).rename (target_file )
156
+
181
157
check_clean_start ()
182
158
self .stop_node (0 )
183
159
0 commit comments