Skip to content

Migrate Python test infra and scripts from httpx to requests - #8419

Closed
Amaury Chamayou (achamayou) wants to merge 5 commits into
mainfrom
achamayou-shiny-meme
Closed

Amaury Chamayou (achamayou) wants to merge 5 commits into
mainfrom
achamayou-shiny-meme

Conversation

@achamayou

Copy link
Copy Markdown
Member

Motivation

The Python e2e infrastructure has been pinned to httpx == 0.23.* because later releases broke the long-forwarding, extended-character-range and JWT tests. requests is the more stable, widely used choice for a synchronous HTTP/1.1 test client, so this migrates all remaining httpx usage to requests.

Implementation summary

  • tests/infra/clients.py: HttpxClient becomes RequestsClient on top of requests.Session. HttpSig is now a requests.auth.AuthBase. Redirects are explicitly disabled at the requests level (CCFClient follows them itself, as before). Exceptions are mapped to the existing TimeoutError / CCFConnectionException / CCFIOException, distinguishing connection-establishment failures from I/O errors on established connections via the wrapped urllib3 error. Response text is always decoded as UTF-8 (matching httpx, rather than requests' charset heuristics). extra_headers_count() remains 5 for HTTP/1.1.
  • tests/connections.py, tests/tvc.py, tests/memberclient.py, scripts/fetch_amd_collateral.py: ported to requests. tvc.py gains an explicit 5s timeout, as requests has no default timeout (httpx did).
  • tests/requirements.txt, scripts/requirements.txt: httpx replaced by requests. doc/historical_ccf_requirements.txt keeps httpx, as older release docs still import it.
  • HTTP/2 dropped from the Python e2e test infra: requests only speaks HTTP/1.1 and CCF's HTTP/2 support is experimental. This removes the e2e_logging_http2 test, the --http2 e2e argument, reqs.no_http2() and all args.http2 branches. node.client() now raises if asked to target a non-HTTP/1.1 interface.
  • tests/client_protocols.py: the h2spec compliance test is kept, targeting a dedicated HTTP2 RPC interface on a node whose primary interface stays HTTP/1.1 (so governance goes through the Python client normally), instead of starting a second all-HTTP/2 network.
  • doc/use_apps/issue_commands.rst: mention requests instead of HTTPX as the example HTTP library.

Safety and compatibility

Test infrastructure and developer scripts only; no runtime, API or ledger-format change. The ccf Python SDK does not depend on httpx or requests. Server-side HTTP/2 support is unchanged and still covered by h2spec in client_protocols; only the Python client-side HTTP/2 test mode is removed.

Replace the httpx-based default e2e client with a requests-based
RequestsClient, port HTTP signature auth to requests.auth.AuthBase, and
switch the remaining scripts (tvc.py, fetch_amd_collateral.py) to
requests.

requests only speaks HTTP/1.1, and HTTP/2 support in CCF is
experimental, so the HTTP/2 mode of the Python e2e infra (--http2 and
the e2e_logging_http2 test) is removed. The h2spec compliance test in
client_protocols.py now targets a dedicated HTTP/2 interface on a node
whose primary interface stays HTTP/1.1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou Amaury Chamayou (achamayou) added the run-long-test Run Long Test job label Sep 22, 2026
…abilise timing-sensitive tests

- Wrap TLS handshake failures as connection-establishment errors so that
  mid-request SSL errors are reported as CCFIOException (as with httpx)
  rather than being retried as connection failures by CCFClient.
- Detect a caller-provided Content-Type header case-insensitively, as
  requests merges headers case-insensitively.
- schema download: sign after every transaction so the chunk count does
  not depend on client speed.
- long-lived forwarding: widen the node-to-node key rotation window, as
  requests issues requests faster than httpx did.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…face node

- caps: refused (503) sessions are torn down asynchronously by the node,
  so wait briefly for the active session count to settle. Tolerate fatal
  errors at shutdown in the low-fd phase regardless of when the expected
  crash is observed, as ledger writes are asynchronous.
- client_protocols: generate the TLS report against a single-interface
  node (as the golden file expects), and run h2spec against a second
  network with an additional dedicated HTTP/2 interface.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
urllib3 >= 2.8 no longer closes pooled connections when a PoolManager is
cleared, relying on garbage collection of the pools instead. Responses
keep a reference to their pool, so a retained response kept its
connection, and the corresponding CCF session, open after the client was
closed. This made the connections caps test see one fewer available
session than expected.

Also close the temporary clients used to follow redirects, which were
never closed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou

Copy link
Copy Markdown
Member Author

Superseded by #8432, which migrates to urllib3 instead of requests so that the Python HTTP/2 e2e coverage (e2e_logging_http2) can be kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-long-test Run Long Test job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant