Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mocktime, coverage_dir): | ||||
self.url = None | self.url = None | ||||
self.log = logging.getLogger('TestFramework.node%d' % i) | self.log = logging.getLogger('TestFramework.node%d' % i) | ||||
def __getattr__(self, *args, **kwargs): | def __getattr__(self, *args, **kwargs): | ||||
"""Dispatches any unrecognised messages to the RPC connection.""" | """Dispatches any unrecognised messages to the RPC connection.""" | ||||
assert self.rpc_connected and self.rpc is not None, "Error: no RPC connection" | assert self.rpc_connected and self.rpc is not None, "Error: no RPC connection" | ||||
return self.rpc.__getattr__(*args, **kwargs) | return self.rpc.__getattr__(*args, **kwargs) | ||||
def start(self): | def start(self, extra_args=None, stderr=None): | ||||
"""Start the node.""" | """Start the node.""" | ||||
self.process = subprocess.Popen( | if extra_args is None: | ||||
self.args + self.extra_args, stderr=self.stderr) | extra_args = self.extra_args | ||||
if stderr is None: | |||||
stderr = self.stderr | |||||
self.process = subprocess.Popen(self.args + extra_args, stderr=stderr) | |||||
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 | ||||
poll_per_s = 4 | poll_per_s = 4 | ||||
for _ in range(poll_per_s * self.rpc_timeout): | for _ in range(poll_per_s * self.rpc_timeout): | ||||
assert self.process.poll( | assert self.process.poll( | ||||
) is None, "bitcoind exited with status %i during initialization" % self.process.returncode | ) is None, "bitcoind exited with status %i during initialization" % self.process.returncode | ||||
try: | try: | ||||
self.rpc = get_rpc_proxy(rpc_url( | self.rpc = get_rpc_proxy(rpc_url(self.datadir, self.index, self.rpchost), | ||||
self.datadir, self.index, self.rpchost), self.index, coveragedir=self.coverage_dir) | self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir) | ||||
self.rpc.getblockcount() | self.rpc.getblockcount() | ||||
# If the call to getblockcount() succeeds then the RPC connection is up | # If the call to getblockcount() succeeds then the RPC connection is up | ||||
self.rpc_connected = True | self.rpc_connected = True | ||||
self.url = self.rpc.url | self.url = self.rpc.url | ||||
self.log.debug("RPC successfully started") | self.log.debug("RPC successfully started") | ||||
return | return | ||||
except IOError as e: | except IOError as e: | ||||
if e.errno != errno.ECONNREFUSED: # Port not yet open? | if e.errno != errno.ECONNREFUSED: # Port not yet open? | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |