Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def remove_default_args(self, args): | ||||
# Remove all occurrences of rm_arg in self.default_args: | # Remove all occurrences of rm_arg in self.default_args: | ||||
# - if the arg is a flag (-flag), then the names must match | # - if the arg is a flag (-flag), then the names must match | ||||
# - if the arg is a value (-key=value) then the name must starts | # - if the arg is a value (-key=value) then the name must starts | ||||
# with "-key=" (the '"' char is to avoid removing "-key_suffix" | # with "-key=" (the '"' char is to avoid removing "-key_suffix" | ||||
# arg is "-key" is the argument to remove). | # arg is "-key" is the argument to remove). | ||||
self.default_args = [def_arg for def_arg in self.default_args | self.default_args = [def_arg for def_arg in self.default_args | ||||
if rm_arg != def_arg and not def_arg.startswith(rm_arg + '=')] | if rm_arg != def_arg and not def_arg.startswith(rm_arg + '=')] | ||||
def start(self, extra_args=None, stdout=None, | def start(self, extra_args=None, *, stdout=None, | ||||
stderr=None, *args, **kwargs): | stderr=None, **kwargs): | ||||
"""Start the node.""" | """Start the node.""" | ||||
if extra_args is None: | if extra_args is None: | ||||
extra_args = self.extra_args | extra_args = self.extra_args | ||||
# Add a new stdout and stderr file each time bitcoind is started | # Add a new stdout and stderr file each time bitcoind is started | ||||
if stderr is None: | if stderr is None: | ||||
stderr = tempfile.NamedTemporaryFile( | stderr = tempfile.NamedTemporaryFile( | ||||
dir=self.stderr_dir, delete=False) | dir=self.stderr_dir, delete=False) | ||||
Show All 15 Lines | def start(self, extra_args=None, *, stdout=None, | ||||
p_args = [self.binary] + self.default_args + extra_args | p_args = [self.binary] + self.default_args + extra_args | ||||
if self.emulator is not None: | if self.emulator is not None: | ||||
p_args = [self.emulator] + p_args | p_args = [self.emulator] + p_args | ||||
self.process = subprocess.Popen( | self.process = subprocess.Popen( | ||||
p_args, | p_args, | ||||
env=subp_env, | env=subp_env, | ||||
stdout=stdout, | stdout=stdout, | ||||
stderr=stderr, | stderr=stderr, | ||||
*args, | |||||
**kwargs) | **kwargs) | ||||
self.running = True | self.running = True | ||||
self.log.debug("bitcoind started, waiting for RPC to come up") | self.log.debug("bitcoind started, waiting for RPC to come up") | ||||
def wait_for_rpc_connection(self): | def wait_for_rpc_connection(self): | ||||
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" | """Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" | ||||
# Poll at a rate of four times per second | # Poll at a rate of four times per second | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def stop_node(self, expected_stderr='', wait=0): | ||||
# Check that stderr is as expected | # Check that stderr is as expected | ||||
self.stderr.seek(0) | self.stderr.seek(0) | ||||
stderr = self.stderr.read().decode('utf-8').strip() | stderr = self.stderr.read().decode('utf-8').strip() | ||||
if stderr != expected_stderr: | if stderr != expected_stderr: | ||||
raise AssertionError( | raise AssertionError( | ||||
"Unexpected stderr {} != {}".format(stderr, expected_stderr)) | "Unexpected stderr {} != {}".format(stderr, expected_stderr)) | ||||
self.stdout.close() | |||||
self.stderr.close() | |||||
del self.p2ps[:] | del self.p2ps[:] | ||||
def is_node_stopped(self): | def is_node_stopped(self): | ||||
"""Checks whether the node has stopped. | """Checks whether the node has stopped. | ||||
Returns True if the node has stopped. False otherwise. | Returns True if the node has stopped. False otherwise. | ||||
This method is responsible for freeing resources (self.process).""" | This method is responsible for freeing resources (self.process).""" | ||||
if not self.running: | if not self.running: | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |