Skip to content

Commit faf9028

Browse files
author
MarcoFalke
committed
test: Check expected_stderr after stop
1 parent 79e8247 commit faf9028

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

test/functional/feature_abortnode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run_test(self):
3636

3737
# Check that node0 aborted
3838
self.log.info("Waiting for crash")
39-
self.nodes[0].wait_until_stopped(timeout=5, expect_error=True)
39+
self.nodes[0].wait_until_stopped(timeout=5, expect_error=True, expected_stderr="Error: A fatal internal error occurred, see debug.log for details")
4040
self.log.info("Node crashed - now verifying restart fails")
4141
self.nodes[0].assert_start_raises_init_error()
4242

test/functional/test_framework/test_node.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,21 +353,13 @@ def stop_node(self, expected_stderr='', *, wait=0, wait_until_stopped=True):
353353
for profile_name in tuple(self.perf_subprocesses.keys()):
354354
self._stop_perf(profile_name)
355355

356-
# Check that stderr is as expected
357-
self.stderr.seek(0)
358-
stderr = self.stderr.read().decode('utf-8').strip()
359-
if stderr != expected_stderr:
360-
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
361-
362-
self.stdout.close()
363-
self.stderr.close()
364-
365356
del self.p2ps[:]
366357

358+
assert (not expected_stderr) or wait_until_stopped # Must wait to check stderr
367359
if wait_until_stopped:
368-
self.wait_until_stopped()
360+
self.wait_until_stopped(expected_stderr=expected_stderr)
369361

370-
def is_node_stopped(self, expected_ret_code=0):
362+
def is_node_stopped(self, *, expected_stderr="", expected_ret_code=0):
371363
"""Checks whether the node has stopped.
372364
373365
Returns True if the node has stopped. False otherwise.
@@ -381,16 +373,25 @@ def is_node_stopped(self, expected_ret_code=0):
381373
# process has stopped. Assert that it didn't return an error code.
382374
assert return_code == expected_ret_code, self._node_msg(
383375
f"Node returned unexpected exit code ({return_code}) vs ({expected_ret_code}) when stopping")
376+
# Check that stderr is as expected
377+
self.stderr.seek(0)
378+
stderr = self.stderr.read().decode('utf-8').strip()
379+
if stderr != expected_stderr:
380+
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
381+
382+
self.stdout.close()
383+
self.stderr.close()
384+
384385
self.running = False
385386
self.process = None
386387
self.rpc_connected = False
387388
self.rpc = None
388389
self.log.debug("Node stopped")
389390
return True
390391

391-
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT, expect_error=False):
392+
def wait_until_stopped(self, *, timeout=BITCOIND_PROC_WAIT_TIMEOUT, expect_error=False, **kwargs):
392393
expected_ret_code = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS
393-
wait_until_helper(lambda: self.is_node_stopped(expected_ret_code=expected_ret_code), timeout=timeout, timeout_factor=self.timeout_factor)
394+
wait_until_helper(lambda: self.is_node_stopped(expected_ret_code=expected_ret_code, **kwargs), timeout=timeout, timeout_factor=self.timeout_factor)
394395

395396
def replace_in_config(self, replacements):
396397
"""

0 commit comments

Comments
 (0)