Merge bitcoin/bitcoin#36504: test: Add missing timeouts for HTTPConnection
What changed, and why it matters
This commit only changes Bitcoin Core's internal test scripts. It adds timeout values to test-only HTTP connections and makes timeout arguments keyword-only in a helper function. There is no change to the actual Bitcoin node software that users run, so it cannot affect live wallets, transactions, or network security.
No security action required. Treat as a normal test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies five files under test/functional/. It passes timeout=self.rpc_timeout (or node.rpc_timeout) to http.client.HTTPConnection in three test scripts, and converts wait_until’s timeout/check_interval parameters to keyword-only in two test-framework classes. These are test-hardening changes that prevent functional tests from hanging indefinitely on broken systems and instead fail with a timeout error. No production code is touched.
Changed components
test/functional/interface_rest.pytest/functional/rpc_users.pytest/functional/rpc_whitelist.pytest/functional/test_framework/test_framework.pytest/functional/test_framework/test_node.pyInspect captured patch +7 / −7
### test/functional/interface_rest.py
@@ -51,7 +51,8 @@ def filter_output_indices_by_value(vouts, value):
if vout['value'] == value:
yield vout['n']
-class RESTTest (BitcoinTestFramework):
+
+class RESTTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [["-rest", "-blockfilterindex=1", "-txindex"], []]
@@ -77,7 +78,7 @@ def test_rest_request(
else:
rest_uri += f'?{urllib.parse.urlencode(query_params)}'
- conn = http.client.HTTPConnection(self.url.hostname, self.url.port)
+ conn = http.client.HTTPConnection(self.url.hostname, self.url.port, timeout=self.rpc_timeout)
self.log.debug(f'{http_method} {rest_uri} {body}')
if http_method == 'GET':
conn.request('GET', rest_uri)
### test/functional/rpc_users.py
@@ -25,7 +25,7 @@ def call_with_auth(node, user, password, method="getbestblockhash"):
url = urllib.parse.urlparse(node.url)
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user, password))}
- conn = http.client.HTTPConnection(url.hostname, url.port)
+ conn = http.client.HTTPConnection(url.hostname, url.port, timeout=node.rpc_timeout)
conn.connect()
conn.request('POST', '/', f'{{"method": "{method}"}}', headers)
resp = conn.getresponse()
### test/functional/rpc_whitelist.py
@@ -19,7 +19,7 @@ def rpccall(node, user, method, *, batch=False):
url = urllib.parse.urlparse(node.url)
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user[0], user[3]))}
request = {"method": method}
- conn = http.client.HTTPConnection(url.hostname, url.port)
+ conn = http.client.HTTPConnection(url.hostname, url.port, timeout=node.rpc_timeout)
conn.connect()
conn.request('POST', '/', json.dumps([request] if batch else request), headers)
resp = conn.getresponse()
@@ -32,7 +32,6 @@ def get_permissions(whitelist):
class RPCWhitelistTest(BitcoinTestFramework):
-
def set_test_params(self):
self.num_nodes = 1
### test/functional/test_framework/test_framework.py
@@ -749,7 +749,7 @@ def sync_all(self, nodes=None):
self.sync_blocks(nodes)
self.sync_mempools(nodes)
- def wait_until(self, test_function, timeout=60, check_interval=0.05):
+ def wait_until(self, test_function, *, timeout=60, check_interval=0.05):
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor, check_interval=check_interval)
def fill_node_addrman(self, *, node_index, address_types_to_add):
### test/functional/test_framework/test_node.py
@@ -909,7 +909,7 @@ def bumpmocktime(self, seconds):
self.mocktime += seconds
self.setmocktime(self.mocktime)
- def wait_until(self, test_function, timeout=60, check_interval=0.05):
+ def wait_until(self, test_function, *, timeout=60, check_interval=0.05):
return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.timeout_factor, check_interval=check_interval)
class TestNodeCLIAttr:Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.