Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show All 26 Lines | |||||
from .util import ( | from .util import ( | ||||
MAX_NODES, | MAX_NODES, | ||||
append_config, | append_config, | ||||
delete_cookie_file, | delete_cookie_file, | ||||
get_auth_cookie, | get_auth_cookie, | ||||
get_rpc_proxy, | get_rpc_proxy, | ||||
p2p_port, | p2p_port, | ||||
rpc_url, | rpc_url, | ||||
wait_until, | wait_until_helper, | ||||
EncodeDecimal, | EncodeDecimal, | ||||
) | ) | ||||
BITCOIND_PROC_WAIT_TIMEOUT = 60 | BITCOIND_PROC_WAIT_TIMEOUT = 60 | ||||
class FailedToStartError(Exception): | class FailedToStartError(Exception): | ||||
"""Raised when a node fails to start correctly.""" | """Raised when a node fails to start correctly.""" | ||||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | def wait_for_rpc_connection(self): | ||||
# Shorter timeout to allow for one retry in case of | # Shorter timeout to allow for one retry in case of | ||||
# ETIMEDOUT | # ETIMEDOUT | ||||
timeout=self.rpc_timeout // 2, | timeout=self.rpc_timeout // 2, | ||||
coveragedir=self.coverage_dir | coveragedir=self.coverage_dir | ||||
) | ) | ||||
rpc.getblockcount() | rpc.getblockcount() | ||||
# If the call to getblockcount() succeeds then the RPC | # If the call to getblockcount() succeeds then the RPC | ||||
# connection is up | # connection is up | ||||
wait_until(lambda: rpc.getmempoolinfo()['loaded']) | wait_until_helper(lambda: rpc.getmempoolinfo()['loaded'], | ||||
timeout_factor=self.timeout_factor) | |||||
# Wait for the node to finish reindex, block import, and | # Wait for the node to finish reindex, block import, and | ||||
# loading the mempool. Usually importing happens fast or | # loading the mempool. Usually importing happens fast or | ||||
# even "immediate" when the node is started. However, there | # even "immediate" when the node is started. However, there | ||||
# is no guarantee and sometimes ThreadImport might finish | # is no guarantee and sometimes ThreadImport might finish | ||||
# later. This is going to cause intermittent test failures, | # later. This is going to cause intermittent test failures, | ||||
# because generally the tests assume the node is fully | # because generally the tests assume the node is fully | ||||
# ready after being started. | # ready after being started. | ||||
# | # | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | def is_node_stopped(self): | ||||
self.running = False | self.running = False | ||||
self.process = None | self.process = None | ||||
self.rpc_connected = False | self.rpc_connected = False | ||||
self.rpc = None | self.rpc = None | ||||
self.log.debug("Node stopped") | self.log.debug("Node stopped") | ||||
return True | return True | ||||
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT): | ||||
wait_until( | wait_until_helper( | ||||
self.is_node_stopped, | self.is_node_stopped, | ||||
timeout=timeout, | timeout=timeout, | ||||
timeout_factor=self.timeout_factor) | timeout_factor=self.timeout_factor) | ||||
@contextlib.contextmanager | @contextlib.contextmanager | ||||
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2): | def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2): | ||||
"""Assert that some debug messages are present within some timeout. | """Assert that some debug messages are present within some timeout. | ||||
Unexpected debug messages may be optionally provided to fail a test | Unexpected debug messages may be optionally provided to fail a test | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | def num_test_p2p_connections(self): | ||||
return len([peer for peer in self.getpeerinfo() | return len([peer for peer in self.getpeerinfo() | ||||
if peer['subver'] == MY_SUBVERSION]) | if peer['subver'] == MY_SUBVERSION]) | ||||
def disconnect_p2ps(self): | def disconnect_p2ps(self): | ||||
"""Close all p2p connections to the node.""" | """Close all p2p connections to the node.""" | ||||
for p in self.p2ps: | for p in self.p2ps: | ||||
p.peer_disconnect() | p.peer_disconnect() | ||||
del self.p2ps[:] | del self.p2ps[:] | ||||
wait_until(lambda: self.num_test_p2p_connections() == 0) | wait_until_helper(lambda: self.num_test_p2p_connections() == 0, | ||||
timeout_factor=self.timeout_factor) | |||||
class TestNodeCLIAttr: | class TestNodeCLIAttr: | ||||
def __init__(self, cli, command): | def __init__(self, cli, command): | ||||
self.cli = cli | self.cli = cli | ||||
self.command = command | self.command = command | ||||
def __call__(self, *args, **kwargs): | def __call__(self, *args, **kwargs): | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |