Skip to content

Commit bf950c4

Browse files
committed
qa: Improve suppressed errors output
Original discussion: bitcoin/bitcoin#30660 (comment)
1 parent 075352e commit bf950c4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

test/functional/feature_framework_startup_failures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run_test(self):
8989
self.log.info("Verifying inability to connect to bitcoind's RPC interface due to wrong port results in one exception containing at least one OSError.")
9090
self._verify_startup_failure(
9191
TestWrongRpcPortStartupFailure, [f"--internal_node_start_duration={node_start_duration}"],
92-
r"AssertionError: \[node 0\] Unable to connect to bitcoind after \d+s \(ignored errors: {[^}]*'OSError \w+'?: \d+[^}]*}, latest error: \w+\([^)]+\)\)"
92+
r"AssertionError: \[node 0\] Unable to connect to bitcoind after \d+s \(ignored errors: {[^}]*'OSError \w+'?: \d+[^}]*}, latest: '[\w ]+'/\w+\([^)]+\)\)"
9393
)
9494

9595
self.log.info("Verifying startup failure due to invalid arg results in only one exception.")

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,13 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
263263
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect."""
264264
# Poll at a rate of four times per second
265265
poll_per_s = 4
266+
266267
suppressed_errors = collections.defaultdict(int)
267-
latest_error = ""
268+
latest_error = None
269+
def suppress_error(category: str, e: Exception):
270+
suppressed_errors[category] += 1
271+
return (category, repr(e))
272+
268273
for _ in range(poll_per_s * self.rpc_timeout):
269274
if self.process.poll() is not None:
270275
# Attach abrupt shutdown error/s to the exception message
@@ -318,8 +323,7 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
318323
# -342 Service unavailable, could be starting up or shutting down
319324
if e.error['code'] not in [-28, -342]:
320325
raise # unknown JSON RPC exception
321-
suppressed_errors[f"JSONRPCException {e.error['code']}"] += 1
322-
latest_error = repr(e)
326+
latest_error = suppress_error(f"JSONRPCException {e.error['code']}", e)
323327
except OSError as e:
324328
error_num = e.errno
325329
# Work around issue where socket timeouts don't have errno set.
@@ -335,16 +339,14 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
335339
errno.ECONNREFUSED # Port not yet open?
336340
]:
337341
raise # unknown OS error
338-
suppressed_errors[f"OSError {errno.errorcode[error_num]}"] += 1
339-
latest_error = repr(e)
342+
latest_error = suppress_error(f"OSError {errno.errorcode[error_num]}", e)
340343
except ValueError as e:
341344
# Suppress if cookie file isn't generated yet and no rpcuser or rpcpassword; bitcoind may be starting.
342345
if "No RPC credentials" not in str(e):
343346
raise
344-
suppressed_errors["missing_credentials"] += 1
345-
latest_error = repr(e)
347+
latest_error = suppress_error("missing_credentials", e)
346348
time.sleep(1.0 / poll_per_s)
347-
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})")
349+
self._raise_assertion_error(f"Unable to connect to bitcoind after {self.rpc_timeout}s (ignored errors: {dict(suppressed_errors)!s}{'' if latest_error is None else f', latest: {latest_error[0]!r}/{latest_error[1]}'})")
348350

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

0 commit comments

Comments
 (0)