Merge bitcoin/bitcoin#32408: tests: Expand HTTP coverage to assert libevent behavior

f16c8c67bf tests: Expand HTTP coverage to assert libevent behavior (Matthew Zipkin)

Pull request description:

  These commits are cherry-picked from #32061  and part of a project to [remove libevent](https://github.com/bitcoin/bitcoin/issues/31194).

  This PR only adds functional tests to `interface_http` to cover some HTTP server behaviors we inherit from libevent, in order to maintain those behaviors when we replace libevent with our own HTTP server.

  1. Pipelining: The server must respond to requests from a client in the order in which they were received [RFC 7230 6.3.2](https://www.rfc-editor.org/rfc/rfc7230#section-6.3.2)
  2. `-rpcservertimeout` config option which sets the amount of time the server will keep an idle client connection alive
  3. "Chunked" Transfer-Encoding: Allows a client to send a request in pieces, without the `Content-Length` header [RFC 7230 4.1](https://www.rfc-editor.org/rfc/rfc7230#section-4.1)

ACKs for top commit:
  achow101:
    ACK f16c8c67bf
  vasild:
    ACK f16c8c67bf
  polespinasa:
    ACK f16c8c67bf
  fjahr:
    utACK f16c8c67bf

Tree-SHA512: 405b59431b4d2bf118fde04b270865dee06ef980ab120d9cc1dce28e5d65dfd880a57055b407009d22f4de614bc3eebdb3e203bcd39e86cb14fbfd62195ed06a
This commit is contained in:
Ava Chow
2025-06-09 13:08:25 -07:00
3 changed files with 139 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ class AuthServiceProxy():
self.__service_url = service_url
self._service_name = service_name
self.ensure_ascii = ensure_ascii # can be toggled on the fly by tests
self.reuse_http_connections = True
self.__url = urllib.parse.urlparse(service_url)
user = None if self.__url.username is None else self.__url.username.encode('utf8')
passwd = None if self.__url.password is None else self.__url.password.encode('utf8')
@@ -92,6 +93,8 @@ class AuthServiceProxy():
raise AttributeError
if self._service_name is not None:
name = "%s.%s" % (self._service_name, name)
if not self.reuse_http_connections:
self._set_conn()
return AuthServiceProxy(self.__service_url, name, connection=self.__conn)
def _request(self, method, path, postdata):
@@ -102,6 +105,8 @@ class AuthServiceProxy():
'User-Agent': USER_AGENT,
'Authorization': self.__auth_header,
'Content-type': 'application/json'}
if not self.reuse_http_connections:
self._set_conn()
self.__conn.request(method, path, postdata, headers)
return self._get_response()

View File

@@ -154,6 +154,7 @@ class TestNode():
self.process = None
self.rpc_connected = False
self.rpc = None
self.reuse_http_connections = True # Must be set before calling get_rpc_proxy() i.e. before restarting node
self.url = None
self.log = logging.getLogger('TestFramework.node%d' % i)
# Cache perf subprocesses here by their data output filename.
@@ -285,6 +286,7 @@ class TestNode():
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
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: