Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | |||||
# The maximum number of nodes a single test can spawn | # The maximum number of nodes a single test can spawn | ||||
MAX_NODES = 8 | MAX_NODES = 8 | ||||
# Don't assign rpc or p2p ports lower than this | # Don't assign rpc or p2p ports lower than this | ||||
PORT_MIN = 11000 | PORT_MIN = 11000 | ||||
# The number of ports to "reserve" for p2p and rpc, each | # The number of ports to "reserve" for p2p and rpc, each | ||||
PORT_RANGE = 5000 | PORT_RANGE = 5000 | ||||
class PortSeed: | |||||
# Must be initialized with a unique integer for each process | |||||
n = None | |||||
def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None): | def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None): | ||||
""" | """ | ||||
Args: | Args: | ||||
url (str): URL of the RPC server to call | url (str): URL of the RPC server to call | ||||
node_number (int): the node number (or id) that this calls to | node_number (int): the node number (or id) that this calls to | ||||
Kwargs: | Kwargs: | ||||
timeout (int): HTTP timeout in seconds | timeout (int): HTTP timeout in seconds | ||||
Show All 10 Lines | def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None): | ||||
proxy.url = url # store URL on proxy for info | proxy.url = url # store URL on proxy for info | ||||
coverage_logfile = coverage.get_filename( | coverage_logfile = coverage.get_filename( | ||||
coveragedir, node_number) if coveragedir else None | coveragedir, node_number) if coveragedir else None | ||||
return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile) | return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile) | ||||
def p2p_port(n): | |||||
assert(n <= MAX_NODES) | |||||
return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | |||||
def rpc_port(n): | |||||
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES) | |||||
def rpc_url(datadir, i, rpchost, rpcport): | def rpc_url(datadir, i, rpchost, rpcport): | ||||
rpc_u, rpc_p = get_auth_cookie(datadir) | rpc_u, rpc_p = get_auth_cookie(datadir) | ||||
host = '127.0.0.1' | host = '127.0.0.1' | ||||
if rpchost: | if rpchost: | ||||
host = rpchost | host = rpchost | ||||
return "http://%s:%s@%s:%d" % (rpc_u, rpc_p, host, int(rpcport)) | return "http://%s:%s@%s:%d" % (rpc_u, rpc_p, host, int(rpcport)) | ||||
# Node functions | # Node functions | ||||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |