Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_node.py
Show First 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | def wait_for_rpc_connection(self): | ||||
try: | try: | ||||
rpc = get_rpc_proxy( | rpc = get_rpc_proxy( | ||||
rpc_url( | rpc_url( | ||||
self.datadir, | self.datadir, | ||||
self.chain, | self.chain, | ||||
self.host, | self.host, | ||||
self.rpc_port), | self.rpc_port), | ||||
self.index, | self.index, | ||||
timeout=self.rpc_timeout, | # Shorter timeout to allow for one retry in case of | ||||
coveragedir=self.coverage_dir) | # ETIMEDOUT | ||||
timeout=self.rpc_timeout // 2, | |||||
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(lambda: rpc.getmempoolinfo()['loaded']) | ||||
# 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 | ||||
Show All 23 Lines | def wait_for_rpc_connection(self): | ||||
# -342 Service unavailable, RPC server started but is shutting down due to error | # -342 Service unavailable, RPC server started but is shutting down due to error | ||||
if e.error['code'] != -28 and e.error['code'] != -342: | if e.error['code'] != -28 and e.error['code'] != -342: | ||||
raise # unknown JSON RPC exception | raise # unknown JSON RPC exception | ||||
except ConnectionResetError: | except ConnectionResetError: | ||||
# This might happen when the RPC server is in warmup, but shut down before the call to getblockcount | # This might happen when the RPC server is in warmup, but shut down before the call to getblockcount | ||||
# succeeds. Try again to properly raise the FailedToStartError | # succeeds. Try again to properly raise the FailedToStartError | ||||
pass | pass | ||||
except OSError as e: | except OSError as e: | ||||
if e.errno != errno.ECONNREFUSED: # Port not yet open? | if e.errno == errno.ETIMEDOUT: | ||||
raise # unknown OS error | # Treat identical to ConnectionResetError | ||||
pass | |||||
elif e.errno == errno.ECONNREFUSED: | |||||
# Port not yet open? | |||||
pass | |||||
else: | |||||
# unknown OS error | |||||
raise | |||||
except ValueError as e: | except ValueError as e: | ||||
# cookie file not found and no rpcuser or rpcpassword; | # cookie file not found and no rpcuser or rpcpassword; | ||||
# bitcoind is still starting | # bitcoind is still starting | ||||
if "No RPC credentials" not in str(e): | if "No RPC credentials" not in str(e): | ||||
raise | raise | ||||
time.sleep(1.0 / poll_per_s) | time.sleep(1.0 / poll_per_s) | ||||
self._raise_assertion_error("Unable to connect to bitcoind") | self._raise_assertion_error("Unable to connect to bitcoind") | ||||
▲ Show 20 Lines • Show All 538 Lines • Show Last 20 Lines |