sturgeon
Record async streams with timing information and replay them deterministically.
What it does
Wraps any Stream, records each item with a timestamp, then lets you replay the recording with the same timing characteristics. Think of it as a DVR for async streams.
use record;
use StreamExt;
let mut recorded = record;
while let Some = recorded.next.await
// Later: replay with original timing
let replay = recorded.recording.replay;
pin!;
while let Some = replay.next.await
Why use it
Deterministic tests for timing-sensitive code. If you're testing rate limiters, batchers, debouncing, backpressure, or any logic that depends on when events arrive - not just what arrives - you need reproducible timing. Sturgeon records real timing patterns once, then replays them identically in tests.
Without sturgeon: sprinkle tokio::time::sleep throughout tests, hope the timing works out, deal with flaky CI.
With sturgeon: record production traffic or realistic patterns once, replay perfectly every time.
Features
- Pass-through recording - items flow through unchanged, timing captured alongside
- Multiple replay modes - original timing, speed-adjusted (2x, 0.5x), or instant
- Persistence - save/load recordings with serde
- Bounded recording -
record_with_capacity(stream, n)keeps only last n items - Partial replay - replay from sequence number, time range, or slice
Writing tests
Record once, replay many times
async
// Test with recorded timing
async
Fast functional tests
async
Speed control
// 2x speed for faster tests
let fast = recording.replay_with_speed;
// Slow motion for debugging
let slow = recording.replay_with_speed;