aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/test_node.py
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2020-04-18 17:03:13 +0200
committerJon Atack <jon@atack.com>2020-04-19 18:12:03 +0200
commitc648e636b2f230db5f1d1137088685f74ae42454 (patch)
tree5252c1dc73b7769b79c26c2f338207f5bd6717d7 /test/functional/test_framework/test_node.py
parentf8102d90889a786a568d62ee4eef13049f8cea00 (diff)
downloadbitcoin-c648e636b2f230db5f1d1137088685f74ae42454.tar.xz
test: add wait_for_cookie_credentials() to test framework
to be able to ensure the cookie file is written and auth credentials available when testing CLI/RPC commands before the RPC connection is up.
Diffstat (limited to 'test/functional/test_framework/test_node.py')
-rwxr-xr-xtest/functional/test_framework/test_node.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 952f773a8f..64f39b8cfe 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -26,6 +26,7 @@ from .util import (
MAX_NODES,
append_config,
delete_cookie_file,
+ get_auth_cookie,
get_rpc_proxy,
rpc_url,
wait_until,
@@ -237,12 +238,27 @@ class TestNode():
except OSError as e:
if e.errno != errno.ECONNREFUSED: # Port not yet open?
raise # unknown OS error
- except ValueError as e: # cookie file not found and no rpcuser or rpcassword. bitcoind still starting
+ except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
if "No RPC credentials" not in str(e):
raise
time.sleep(1.0 / poll_per_s)
self._raise_assertion_error("Unable to connect to bitcoind after {}s".format(self.rpc_timeout))
+ def wait_for_cookie_credentials(self):
+ """Ensures auth cookie credentials can be read, e.g. for testing CLI with -rpcwait before RPC connection is up."""
+ self.log.debug("Waiting for cookie credentials")
+ # Poll at a rate of four times per second.
+ poll_per_s = 4
+ for _ in range(poll_per_s * self.rpc_timeout):
+ try:
+ get_auth_cookie(self.datadir, self.chain)
+ self.log.debug("Cookie credentials successfully retrieved")
+ return
+ except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
+ pass # so we continue polling until RPC credentials are retrieved
+ time.sleep(1.0 / poll_per_s)
+ self._raise_assertion_error("Unable to retrieve cookie credentials after {}s".format(self.rpc_timeout))
+
def generate(self, nblocks, maxtries=1000000):
self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries)