Enable the testkit
The testkit feature adds wireframe::testkit: drivers that run a real WireframeApp over an in-memory duplex stream, with no socket and no server. A driver encodes requests with a codec, feeds the bytes in, and returns the decoded replies. Turn the feature on for tests only, through a dev-dependency or a feature of the crate under test.
Every sample on this site that does not need a real socket is tested this way, including the routing, codec, and middleware guides.
One byte at a time
TCP delivers bytes, not frames. A codec that only works when a frame arrives in one read is a codec with a bug waiting for a busy network. drive_with_partial_frames concatenates the encoded requests and writes them in chunks of a chosen size, down to one byte:
let codec = LengthDelimitedFrameCodec::new(1024);
let one = NonZeroUsize::new(1).expect("non-zero");
let replies = drive_with_partial_frames(app(), &codec, vec![request(b"a"), request(b"b")], one)
.await
.expect("the app answers");
assert_eq!(replies, vec![request(b"a"), request(b"b")]);
The helper builds requests by serializing an Envelope with BincodeSerializer, the application’s default. The echo application returns each request unchanged, so the replies equal the requests. drive_with_partial_codec_frames returns decoded codec frames instead of payloads, for checking header fields.
Feed fragments
drive_with_fragments takes a raw payload and a Fragmenter, fragments the payload, wraps each fragment in an envelope, and feeds the frames through the application. The fragmentation guide’s sample uses it with a 2,000-byte request and 256-byte fragments. drive_with_partial_fragments combines both drivers, fragmenting and then chunking.
wireframe::testkit::reassembly adds assertions over reassembly and message-assembly state, such as whether a message is still incomplete, how many bytes are buffered, and which error ended an assembly. They return a result rather than panicking, so they work in rstest tests and in rstest-bdd steps.
Slow readers and writers
Slow reads and writes expose timing assumptions. SlowIoPacing sets a chunk size and a delay between chunks, while SlowIoConfig applies separate pacing to the writer and reader and sets the duplex capacity. This short exchange exercises pacing; it does not fill the 64-byte buffer or prove back-pressure:
let pace = |bytes: usize| {
SlowIoPacing::new(
NonZeroUsize::new(bytes).expect("non-zero"),
Duration::from_millis(5),
)
};
let config = SlowIoConfig::new()
.with_writer_pacing(pace(8))
.with_reader_pacing(pace(32))
.with_capacity(64);
let replies = drive_with_slow_codec_payloads(app(), &codec, vec![request(b"slow")], config)
.await
.expect("the app answers");
assert_eq!(replies, vec![request(b"slow")]);
The test runs with #[tokio::test(start_paused = true)], so the delays advance virtual time and the test finishes at once. This request and reply stay below the duplex capacity, so the test verifies pacing only. To exercise capacity back-pressure, send a reply larger than the duplex capacity but smaller than the codec’s frame limit while the reader is paced.
Beyond the testkit
The separate wireframe_testing crate, also at 0.4.0-alpha1, re-exports the testkit and adds more: codec-aware drivers that return payloads or frames for any codec, Hotline-framed fixtures for valid, oversized, truncated, and correlated frames, an observability handle that captures logs and metrics together, a harness that starts a real server and a connected client in one test (spawn_wireframe_pair), prepared drivers that prove middleware is built once (prepare_and_drive_with_frames, drive_prepared_with_frames), and allocation counting for benchmarks (benchmark_alloc_support). This site’s samples use the main crate’s testkit.
For servers and clients that must meet over a real socket, the getting-started program is itself a pattern: bind to port 0, read local_addr, call spawn, and finish with stop and drained. Shutdown closes idle connections, so the client may still be open. A tracked connection task can delay drained. Use tokio::time::timeout to bound the test.
The server lifecycle harness starts a configured, unbound server on loopback. spawn_wireframe_server waits for readiness and returns a handle with the bound address. Leave ready_signal unset for the harness. Dropping the handle requests shutdown. Await shutdown() to observe the drain within the configured timeout.

