From 7e3b60584b365a99ee240380e9d6de4c3809a7c7 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:06:13 +0200 Subject: [PATCH 1/4] refactor(qa): Simplify through using assert_raises() --- test/functional/interface_http.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/functional/interface_http.py b/test/functional/interface_http.py index 58ee6289ac4..10d26592b74 100755 --- a/test/functional/interface_http.py +++ b/test/functional/interface_http.py @@ -6,7 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.netutil import NETWORK_ERRORS -from test_framework.util import assert_equal, str_to_b64str +from test_framework.util import assert_equal, assert_raises, str_to_b64str import concurrent.futures import http.client @@ -278,14 +278,10 @@ class HTTPBasicsTest (BitcoinTestFramework): else: conn.post_raw('/', '{"method": "getblockcount"}') - try: - # The server should not respond to the second request until the first - # request has been handled. Since the server will not respond at all - # to the first request until we generate a block we expect a socket timeout. - conn.recv_raw() - assert False - except TimeoutError: - pass + # The server should not respond to the second request until the first + # request has been handled. Since the server will not respond at all + # to the first request until we generate a block we expect a socket timeout. + assert_raises(TimeoutError, lambda: conn.recv_raw()) # Use a separate http connection to generate a block self.generate(self.node, 1, sync_fun=self.no_op) @@ -649,11 +645,7 @@ class HTTPBasicsTest (BitcoinTestFramework): ): conn = BitcoinHTTPConnection(self.node) conn.set_timeout(5) - try: - conn.post('/', '{"method": "never_accepted"}', connection_header='keep-alive').read() - assert False, "Connection succeeded unexpectedly" - except TimeoutError: - pass + assert_raises(TimeoutError, lambda: conn.post('/', '{"method": "never_accepted"}', connection_header='keep-alive').read()) # All original clients are still connected assert_equal(len(connections), MAX_HTTP_CONNECTIONS) From 6d570415a018dd2fb43486c97427bcea03c0add1 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:10:19 +0200 Subject: [PATCH 2/4] refactor(qa): Move check right below related check --- test/functional/feature_init.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 283a67ec774..4fa88bb200e 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -378,6 +378,16 @@ class InitTest(BitcoinTestFramework): match=ErrorMatch.PARTIAL_REGEX ) + # Start without the HTTP server to ensure that -rpcmaxconnections is ignored + with node.assert_debug_log( + expected_msgs = ["net thread start"], + unexpected_msgs = ["Initialized HTTP server"], + timeout = 10 + ): + node.start(extra_args=[f"-rpcmaxconnections={2**64}", "-server=0"]) + # No HTTP server, no RPC `stop` + node.kill_process() + if self.RLIM_INFINITY is not None: # Get the platform's file descriptor limit, if possible import resource @@ -408,16 +418,6 @@ class InitTest(BitcoinTestFramework): match=ErrorMatch.PARTIAL_REGEX ) - # Start without the HTTP server to ensure that -rpcmaxconnections is ignored - with node.assert_debug_log( - expected_msgs = ["net thread start"], - unexpected_msgs = ["Initialized HTTP server"], - timeout = 10 - ): - node.start(extra_args=[f"-rpcmaxconnections={2**64}", "-server=0"]) - # No HTTP server, no RPC `stop` - node.kill_process() - def run_test(self): self.init_pid_test() self.init_stress_test_interrupt() From 6248331b295c5540399cd7754e03a19c93b24318 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 24 Aug 2026 21:11:16 +0200 Subject: [PATCH 3/4] qa: Switch to warning when skipping tests This is convention, see of example "except SkipTest" in test_framework.py. --- test/functional/feature_init.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 4fa88bb200e..694404e3f91 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -336,7 +336,7 @@ class InitTest(BitcoinTestFramework): try: resource.setrlimit(resource.RLIMIT_NOFILE, (limit, hard)) except (ValueError, OSError): - self.log.info(f"Skipping rlimit test: cannot set soft limit (hard={hard})") + self.log.warning(f"Skipping rlimit test: cannot set soft limit (hard={hard})") return try: self.restart_node(1) @@ -348,7 +348,7 @@ class InitTest(BitcoinTestFramework): def init_rlimit_test(self): """Test that bitcoind starts correctly when the soft RLIMIT_NOFILE limit is RLIM_INFINITY.""" if self.RLIM_INFINITY is None: - self.log.info("Skipping: resource module not available") + self.log.warning("Skipping: resource module not available") return self.log.info("Testing node startup with RLIM_INFINITY fd limit") @@ -357,7 +357,7 @@ class InitTest(BitcoinTestFramework): def init_rlimit_large_test(self): """Test that bitcoind starts correctly when the soft RLIMIT_NOFILE limit is above INT_MAX.""" if self.RLIM_INFINITY is None: - self.log.info("Skipping: resource module not available") + self.log.warning("Skipping: resource module not available") return self.log.info("Testing node startup with fd limit above INT_MAX") @@ -399,7 +399,7 @@ class InitTest(BitcoinTestFramework): try: resource.setrlimit(resource.RLIMIT_NOFILE, (soft, soft)) except (ValueError, OSError): - self.log.info(f"Skipping rlimit test: cannot reduce hard limit (soft={soft}, hard={hard})") + self.log.warning(f"Skipping rlimit test: cannot reduce hard limit (soft={soft}, hard={hard})") return self.log.info("Checking that large -maxconnections setting gets adjusted for available file descriptors") From 290be9eafa488dd49820b3bb5698391c0abbc6a2 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:13:55 +0200 Subject: [PATCH 4/4] qa: Minor feature_init.py improvements * Emit log message before performing check. * Drop needless 'r' from string literal. --- test/functional/feature_init.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 694404e3f91..60de66c528e 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -378,7 +378,7 @@ class InitTest(BitcoinTestFramework): match=ErrorMatch.PARTIAL_REGEX ) - # Start without the HTTP server to ensure that -rpcmaxconnections is ignored + self.log.info("Checking -rpcmaxconnections is ignored when disabling the HTTP server") with node.assert_debug_log( expected_msgs = ["net thread start"], unexpected_msgs = ["Initialized HTTP server"], @@ -406,7 +406,7 @@ class InitTest(BitcoinTestFramework): # Note this prints a message to the log and stderr but does not abort the process with node.assert_debug_log(expected_msgs=[f"Reducing -maxconnections from {soft} "]): self.restart_node(1, extra_args=[f"-maxconnections={soft}"]) - self.stop_node(1, expected_stderr=re.compile(fr"Reducing -maxconnections from {soft} ")) + self.stop_node(1, expected_stderr=re.compile(f"Reducing -maxconnections from {soft} ")) # From httpserver.h DEFAULT_MAX_HTTP_CONNECTIONS = 16