Skip to main content

Module connection

Module connection 

Source
Available on crate features default-client and wire-mock and test-util only.
Expand description

A deterministic harness for testing connection-level client behavior.

Each endpoint assigns one complete ConnectionScript to each accepted connection. An Http1Script parses requests and emits typed responses, while a SocketScript runs ordered byte-level actions for malformed framing, partial I/O, resets, and other transport behavior.

ManualGate synchronizes a test with a script without relying on elapsed time. Reaching a gate records an arrival and blocks the script until the gate is released. Release is permanent, so current and future waiters all pass.

The harness records DNS lookups, accepted connections, parsed HTTP/1 requests, and connection closure. Its wait methods observe those events and also surface failures from endpoint and connection tasks. Call ConnectionTestHarness::shutdown at the end of a test to join those tasks and report any background failure; dropping the harness only aborts them.

§Script ownership

Scripts describe connections, not requests. A queued endpoint plan moves one script to each connection in order. Repeated plans clone a complete script for each connection. Requests served over one keep-alive connection remain within that connection’s script.

§Extension via SocketScript

SocketScript is the extension point for framing the typed API does not model; interim 1xx exchanges, for example, are expressible by adding byte-level actions without changing existing scripts.

Structs§

BodyPlan
A complete HTTP/1 response body, optionally paused at a gate.
ConnectionId
The identity assigned to an accepted connection.
ConnectionScript
A complete high-level or byte-level script for one accepted connection.
ConnectionTestHarness
Running scripted endpoints with recorded connection events and mock DNS.
EndpointPlan
Assigns a complete ConnectionScript to each accepted connection.
GateWaiter
A script-side handle for a ManualGate.
HarnessBuilder
Configures endpoints and DNS entries for a ConnectionTestHarness.
HarnessError
An error produced by the connection test harness.
Http1Response
One HTTP/1 response emitted by a script.
Http1Script
A typed HTTP/1 script for one connection.
ManualGate
A one-shot broadcast gate used to synchronize a test with one or more scripts.
MockDnsResolver
A DNS resolver backed by entries configured on the harness.
SocketScript
An ordered sequence of low-level socket actions for one connection.
TestEndpoint
A bound endpoint managed by a ConnectionTestHarness.

Enums§

ConnectionCloseReason
Why a connection task stopped.
ConnectionEvent
An event recorded by the harness.
Finish
What a finite HTTP/1 script does after sending its final response.