Skip to content

Commit

Permalink
qa: Add feature_framework_rpc_failure_details.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hodlinator committed Jan 9, 2025
1 parent 23bc6bf commit d70ac9c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
55 changes: 55 additions & 0 deletions test/functional/feature_framework_rpc_failure_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Verify timing out in connecting to bitcoind's RPC interface throws an exception
including details on what kind of failures happened before timing out.
"""

from test_framework.test_node import (
FailedToStartError,
TestNode,
)
from test_framework.util import (
assert_raises_message,
rpc_port,
)
from test_framework.test_framework import BitcoinTestFramework

import re

class FeatureFrameworkRPCFailureDetails(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
# Lower the timeout so we don't wait that long
self.rpc_timeout = 2

# Overridden to avoid syncing non-started nodes.
def setup_network(self):
self.setup_nodes()

# Overridden to avoid starting nodes before run_test.
def setup_nodes(self):
self.add_nodes(self.num_nodes, self.extra_args)

def run_test(self):
e = assert_raises_message(
exc=AssertionError,
message="[node 0] Unable to connect to bitcoind after ",
fun=BitcoinTestFramework.start_node,
self=self,
i=0,
# Override RPC port to something TestNode isn't expecting so that we are
# unable to establish an RPC connection.
extra_args=[f'-rpcport={rpc_port(2)}'],
)
assert re.match(
r"^\[node 0\] Unable to connect to bitcoind after \d*s \(ignored errors: {'.*'OSError .*': .*, latest error: .*$", \
str(e)), \
f'Didn\'t find expected details in "{e}"'
self.log.info("One WARNING expected - Explicitly stopping the node to verify it completes cleanly during the test")
self.nodes[0].stop_node(avoid_exceptions=True)

if __name__ == '__main__':
FeatureFrameworkRPCFailureDetails(__file__).main()
3 changes: 2 additions & 1 deletion test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def assert_greater_than_or_equal(thing1, thing2):


def assert_raises(exc, fun, *args, **kwds):
assert_raises_message(exc, None, fun, *args, **kwds)
return assert_raises_message(exc, None, fun, *args, **kwds)


def assert_raises_message(exc, message, fun, *args, **kwds):
Expand All @@ -100,6 +100,7 @@ def assert_raises_message(exc, message, fun, *args, **kwds):
if message is not None and message not in str(e):
raise AssertionError(
f"Expected substring not found in error:\nsubstring: '{message}'\nerror: '{str(e)}'.")
return e
except Exception as e:
raise AssertionError("Unexpected exception raised: " + type(e).__name__)
else:
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
'feature_dirsymlinks.py',
'feature_help.py',
'feature_framework_rpc_failure.py',
'feature_framework_rpc_failure_details.py',
'feature_shutdown.py',
'wallet_migration.py',
'p2p_ibd_txrelay.py',
Expand Down

0 comments on commit d70ac9c

Please sign in to comment.