MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / is_node_stopped

Method is_node_stopped

test/functional/test_framework/test_node.py:484–523  ·  view source on GitHub ↗

Checks whether the node has stopped. Returns True if the node has stopped. False otherwise. If the process has exited, asserts that the exit code matches `expected_ret_code` (which may be a single value or an iterable of values), and that stderr matches `expected_st

(self, *, expected_stderr="", expected_ret_code=0)

Source from the content-addressed store, hash-verified

482 self.wait_until_stopped(expected_stderr=expected_stderr)
483
484 def is_node_stopped(self, *, expected_stderr="", expected_ret_code=0):
485 """Checks whether the node has stopped.
486
487 Returns True if the node has stopped. False otherwise.
488
489 If the process has exited, asserts that the exit code matches
490 `expected_ret_code` (which may be a single value or an iterable of values),
491 and that stderr matches `expected_stderr` exactly or, if a regex pattern is
492 provided, contains the pattern.
493
494 This method is responsible for freeing resources (self.process)."""
495 if not self.running:
496 return True
497 return_code = self.process.poll()
498 if return_code is None:
499 return False
500
501 # process has stopped. Assert that it didn't return an error code.
502 if not isinstance(expected_ret_code, Iterable):
503 expected_ret_code = (expected_ret_code,)
504 assert return_code in expected_ret_code, self._node_msg(
505 f"Node returned unexpected exit code ({return_code}) vs ({expected_ret_code}) when stopping")
506 # Check that stderr is as expected
507 self.stderr.seek(0)
508 stderr = self.stderr.read().decode('utf-8').strip()
509 if isinstance(expected_stderr, re.Pattern):
510 if not expected_stderr.search(stderr):
511 raise AssertionError(f"Unexpected stderr {stderr!r} does not contain {expected_stderr.pattern!r}")
512 elif stderr != expected_stderr:
513 raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
514
515 self.stdout.close()
516 self.stderr.close()
517
518 self.running = False
519 self.process = None
520 self.rpc_connected = False
521 self._rpc = None
522 self.log.debug("Node stopped")
523 return True
524
525 def wait_until_stopped(self, *, timeout=BITCOIND_PROC_WAIT_TIMEOUT, expect_error=False, **kwargs):
526 if "expected_ret_code" not in kwargs:

Callers 4

wait_until_stoppedMethod · 0.95
kill_processMethod · 0.95
async_routineMethod · 0.80
test_norpccookiefileMethod · 0.80

Calls 6

_node_msgMethod · 0.95
formatMethod · 0.80
seekMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected