|
26 | 26 | MAX_NODES,
|
27 | 27 | append_config,
|
28 | 28 | delete_cookie_file,
|
| 29 | + get_auth_cookie, |
29 | 30 | get_rpc_proxy,
|
30 | 31 | rpc_url,
|
31 | 32 | wait_until,
|
@@ -237,12 +238,27 @@ def wait_for_rpc_connection(self):
|
237 | 238 | except OSError as e:
|
238 | 239 | if e.errno != errno.ECONNREFUSED: # Port not yet open?
|
239 | 240 | raise # unknown OS error
|
240 |
| - except ValueError as e: # cookie file not found and no rpcuser or rpcassword. bitcoind still starting |
| 241 | + except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting |
241 | 242 | if "No RPC credentials" not in str(e):
|
242 | 243 | raise
|
243 | 244 | time.sleep(1.0 / poll_per_s)
|
244 | 245 | self._raise_assertion_error("Unable to connect to bitcoind after {}s".format(self.rpc_timeout))
|
245 | 246 |
|
| 247 | + def wait_for_cookie_credentials(self): |
| 248 | + """Ensures auth cookie credentials can be read, e.g. for testing CLI with -rpcwait before RPC connection is up.""" |
| 249 | + self.log.debug("Waiting for cookie credentials") |
| 250 | + # Poll at a rate of four times per second. |
| 251 | + poll_per_s = 4 |
| 252 | + for _ in range(poll_per_s * self.rpc_timeout): |
| 253 | + try: |
| 254 | + get_auth_cookie(self.datadir, self.chain) |
| 255 | + self.log.debug("Cookie credentials successfully retrieved") |
| 256 | + return |
| 257 | + except ValueError: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting |
| 258 | + pass # so we continue polling until RPC credentials are retrieved |
| 259 | + time.sleep(1.0 / poll_per_s) |
| 260 | + self._raise_assertion_error("Unable to retrieve cookie credentials after {}s".format(self.rpc_timeout)) |
| 261 | + |
246 | 262 | def generate(self, nblocks, maxtries=1000000):
|
247 | 263 | self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
|
248 | 264 | return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries)
|
|
0 commit comments