From fa2a3683d519f0711860e9411aa19b353a738819 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 20 May 2026 14:00:25 +0200 Subject: [PATCH] test: Allow mining_getblocktemplate_longpoll.py --usecli Part of the diff can be reviewed with --ignore-all-space --- .../mining_getblocktemplate_longpoll.py | 8 ++--- test/functional/test_framework/test_node.py | 30 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/test/functional/mining_getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py index e36396b352a..e2293f96e18 100755 --- a/test/functional/mining_getblocktemplate_longpoll.py +++ b/test/functional/mining_getblocktemplate_longpoll.py @@ -8,7 +8,7 @@ import random import threading from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, get_rpc_proxy +from test_framework.util import assert_equal from test_framework.wallet import MiniWallet @@ -18,9 +18,8 @@ class LongpollThread(threading.Thread): # query current longpollid template = node.getblocktemplate({'rules': ['segwit']}) self.longpollid = template['longpollid'] - # create a new connection to the node, we can't use the same - # connection from two threads - self.node = get_rpc_proxy(node.url, 1, timeout=600, coveragedir=node.coverage_dir) + # create a new connection to the node for this thread + self.node = node.create_new_rpc_connection(client_timeout=600) def run(self): self.node.getblocktemplate({'longpollid': self.longpollid, 'rules': ['segwit']}) @@ -28,7 +27,6 @@ class LongpollThread(threading.Thread): class GetBlockTemplateLPTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - self.supports_cli = False def run_test(self): self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.") diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index c3384007b36..6254e5f063c 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -76,6 +76,9 @@ class ErrorMatch(Enum): PARTIAL_REGEX = 3 +RPCConnectionType = Enum("RPCConnectionType", ["AUTO", "AUTHPROXY", "CLI"]) + + class TestNode(): """A class for representing a bitcoind node under test. @@ -301,16 +304,23 @@ class TestNode(): if self.start_perf: self._start_perf() - def create_new_rpc_connection(self): + def create_new_rpc_connection(self, *, mode="AUTO", client_timeout=None): """Create an additional RPC connection, likely to be used in a new thread.""" - rpc = get_rpc_proxy( - rpc_url(self.datadir_path, self.index, self.chain, self.rpchost), - self.index, - timeout=self.rpc_timeout // 2, # Shorter timeout to allow for one retry in case of ETIMEDOUT - coveragedir=self.coverage_dir, - ) - rpc.auth_service_proxy_instance.reuse_http_connections = self.reuse_http_connections - return rpc + mode = RPCConnectionType[mode] + if mode == RPCConnectionType.AUTO: + mode = RPCConnectionType.CLI if self.use_cli else RPCConnectionType.AUTHPROXY + client_timeout = client_timeout or (self.rpc_timeout // 2) # Shorter timeout to allow for one retry in case of ETIMEDOUT + if mode == RPCConnectionType.AUTHPROXY: + rpc = get_rpc_proxy( + rpc_url(self.datadir_path, self.index, self.chain, self.rpchost), + self.index, + timeout=client_timeout, + coveragedir=self.coverage_dir, + ) + rpc.auth_service_proxy_instance.reuse_http_connections = self.reuse_http_connections + return rpc + else: # mode==CLI + return self.cli(f"-rpcclienttimeout={client_timeout}") def wait_for_rpc_connection(self, *, wait_for_import=True): """Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" @@ -333,7 +343,7 @@ class TestNode(): raise FailedToStartError(self._node_msg( f'bitcoind exited with status {self.process.returncode} during initialization. {str_error}')) try: - rpc = self.create_new_rpc_connection() + rpc = self.create_new_rpc_connection(mode="AUTHPROXY") rpc.getblockcount() # If the call to getblockcount() succeeds then the RPC connection is up if self.version_is_at_least(190000) and wait_for_import: