diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 283a67ec774..60de66c528e 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") @@ -378,6 +378,16 @@ class InitTest(BitcoinTestFramework): match=ErrorMatch.PARTIAL_REGEX ) + 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"], + 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 @@ -389,14 +399,14 @@ 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") # 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 @@ -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() 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)