@@ -307,21 +307,30 @@ def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
307307 wait_until (self .is_node_stopped , timeout = timeout )
308308
309309 @contextlib .contextmanager
310- def assert_debug_log (self , expected_msgs ):
310+ def assert_debug_log (self , expected_msgs , timeout = 2 ):
311+ time_end = time .time () + timeout
311312 debug_log = os .path .join (self .datadir , self .chain , 'debug.log' )
312313 with open (debug_log , encoding = 'utf-8' ) as dl :
313314 dl .seek (0 , 2 )
314315 prev_size = dl .tell ()
315316 try :
316317 yield
317318 finally :
318- with open (debug_log , encoding = 'utf-8' ) as dl :
319- dl .seek (prev_size )
320- log = dl .read ()
321- print_log = " - " + "\n - " .join (log .splitlines ())
322- for expected_msg in expected_msgs :
323- if re .search (re .escape (expected_msg ), log , flags = re .MULTILINE ) is None :
324- self ._raise_assertion_error ('Expected message "{}" does not partially match log:\n \n {}\n \n ' .format (expected_msg , print_log ))
319+ while True :
320+ found = True
321+ with open (debug_log , encoding = 'utf-8' ) as dl :
322+ dl .seek (prev_size )
323+ log = dl .read ()
324+ print_log = " - " + "\n - " .join (log .splitlines ())
325+ for expected_msg in expected_msgs :
326+ if re .search (re .escape (expected_msg ), log , flags = re .MULTILINE ) is None :
327+ found = False
328+ if found :
329+ return
330+ if time .time () >= time_end :
331+ break
332+ time .sleep (0.05 )
333+ self ._raise_assertion_error ('Expected messages "{}" does not partially match log:\n \n {}\n \n ' .format (str (expected_msgs ), print_log ))
325334
326335 @contextlib .contextmanager
327336 def assert_memory_usage_stable (self , * , increase_allowed = 0.03 ):
0 commit comments