Merge bitcoin/bitcoin#36064: qa: Minor improvement follow-ups to 35730

290be9eafa qa: Minor feature_init.py improvements (Hodlinator)
6248331b29 qa: Switch to warning when skipping tests (Hodlinator)
6d570415a0 refactor(qa): Move check right below related check (Hodlinator)
7e3b60584b refactor(qa): Simplify through using assert_raises() (Hodlinator)

Pull request description:

  * Simplify code through `assert_raises()` - https://github.com/bitcoin/bitcoin/pull/35730#discussion_r3812910717
  * Move check below related check - https://github.com/bitcoin/bitcoin/pull/35730#discussion_r3812910717
  * Warn when skipping checks - https://github.com/bitcoin/bitcoin/pull/35730#discussion_r3813035181
  * Minor improvements in 1 commit:
    * Log message instead of comment - https://github.com/bitcoin/bitcoin/pull/35730#discussion_r3814377374
    * Drop `r` from string literal prefix - https://github.com/bitcoin/bitcoin/pull/35730#discussion_r3814347609

ACKs for top commit:
  pinheadmz:
    ACK 290be9eafa
  winterrdog:
    tACK 290be9eafa

Tree-SHA512: 528a9701bc7529c74c02d56f0ca498dc2c0165e7d5a4ca5c8f35f7887e89df6898db9a5077811bed3d5318116479e1c974e9979a9b0c93eb72ed1d467fd8f01d
This commit is contained in:
merge-script
2026-08-25 10:10:22 +01:00
2 changed files with 21 additions and 29 deletions

View File

@@ -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()

View File

@@ -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)