Skip to content

Commit 6ad21b4

Browse files
committed
qa: Include ignored errors in RPC connection timeout
When an RPC connection attempt with bitcoind times out, include which ignored errors occurred in the exception message. May provide clues of what has gone wrong.
1 parent 879243e commit 6ad21b4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2017-2022 The Bitcoin Core developers
2+
# Copyright (c) 2017-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Class for bitcoind node under test"""
@@ -265,6 +265,8 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
265265
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect."""
266266
# Poll at a rate of four times per second
267267
poll_per_s = 4
268+
suppressed_errors = collections.defaultdict(int)
269+
latest_error = ""
268270
for _ in range(poll_per_s * self.rpc_timeout):
269271
if self.process.poll() is not None:
270272
# Attach abrupt shutdown error/s to the exception message
@@ -317,6 +319,8 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
317319
# -342 Service unavailable, could be starting up or shutting down
318320
if e.error['code'] not in [-28, -342]:
319321
raise # unknown JSON RPC exception
322+
suppressed_errors[f"JSONRPCException {e.error['code']}"] += 1
323+
latest_error = repr(e)
320324
except OSError as e:
321325
# Suppress similarly to the above JSONRPCException errors.
322326
if e.errno not in [
@@ -326,12 +330,16 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
326330
errno.ECONNREFUSED # Port not yet open?
327331
]:
328332
raise # unknown OS error
333+
suppressed_errors[f"OSError {errno.errorcode[e.errno]}"] += 1
334+
latest_error = repr(e)
329335
except ValueError as e:
330336
# Suppress if cookie file isn't generated yet and no rpcuser or rpcpassword; bitcoind may be starting.
331337
if "No RPC credentials" not in str(e):
332338
raise
339+
suppressed_errors["missing_credentials"] += 1
340+
latest_error = repr(e)
333341
time.sleep(1.0 / poll_per_s)
334-
self._raise_assertion_error("Unable to connect to bitcoind after {}s".format(self.rpc_timeout))
342+
self._raise_assertion_error(f"Unable to connect to bitcoind after {self.rpc_timeout}s (ignored errors: {str(dict(suppressed_errors))}, latest error: {latest_error})")
335343

336344
def wait_for_cookie_credentials(self):
337345
"""Ensures auth cookie credentials can be read, e.g. for testing CLI with -rpcwait before RPC connection is up."""

0 commit comments

Comments
 (0)