Testing¶
Stdlib-only instruments, shipped with the library so your integration tests and clientwright's own suite run on the same ground. Usage patterns: Guide → Testing your service.
Fault-injecting origin¶
Fault-injecting HTTP origin on the standard library, for conformance tests.
Routes:
- /echo 200 with a small JSON body (method, path, headers echo)
- /status/{code} responds with that status
- /slow/{seconds} sleeps, then 200
- /redirect/{n} 302 chain of n hops ending at /echo
- /redirect-loop 302 to itself forever
- /flaky/{key}/{fails} first {fails} requests per key answer 503, then 200
- /retry-after/{seconds} 503 with a Retry-After header
- /disconnect closes the connection without a response
Chaos routes (mid-stream and protocol-level faults):
- /hang-body/{seconds} 200 announcing 10 bytes: 3 arrive, the rest after the stall
- /drop-body 200 announcing 10 bytes but the connection dies after 3
- /garbage raw non-HTTP bytes instead of a status line
- /reset hard TCP reset (SO_LINGER 0) instead of a response
- /flaky-disconnect/{key}/{fails} first {fails} requests per key drop the connection, then 200
OriginServer
¶
Bases: ThreadingHTTPServer
Context-managed origin bound to an ephemeral localhost port.
Source code in clientwright/core/testing/origin.py
handle_error(request, client_address)
¶
Deterministic doubles¶
Deterministic doubles for engine and telemetry tests.
ManualClock
¶
Monotonic clock advanced by hand.
Source code in clientwright/core/testing/doubles.py
RecordingMetrics
dataclass
¶
ClientMetricsProtocol implementation that remembers every record.