moonpool ~
GitHub →
$ moonpool · deterministic simulation testing for Rust

One seed, one exact run

Write your system once against provider traits. In tests, moonpool runs it in one thread on a simulated network, disk and clock, and injects faults. In production, the same code runs on Tokio. A failure gives you a seed, and the seed replays the failure.

The small system of the site (moonpool-wasm-demo): three servers keep one value on disk, and a client writes it to a quorum and reads it back, with network faults and reboots on. The page first shows the run that a Rust test recorded. Then it loads moonpool, compiled to wasm, and runs the same seed in your browser. The network, the disk and the clock are simulated. Type another seed to see another run.

Provider traits6
Chaos surfaces8
Assertion macros9
Mocksnone
01What you get
  • A run you can replayOne seed feeds each random draw: the order of the tasks, the latency of each message, each fault. The same seed gives the same run.
  • The same codeTokioProviders in production, SimProviders in tests. No Sim* copy of your types, no test-only hook in the product.
  • Faults by defaultPartitions, clogs, torn writes, lost directory entries, reboots, slow machines, clocks that drift. Each seed draws its own set.
  • Faults inside your codehint!("batch durable, not sent") names a moment. The simulator decides to strike there. buggify! forces a rare branch. Both do nothing in production.
  • Assertions that must fireassert_sometimes! names a rare path. If no seed reaches it, the run fails: a fault that never fires tests nothing.
  • ExplorationThe explorer forks a run at each discovery and searches the timelines near it.
  • Runs in a browserThe simulator has no syscall on its path, so it compiles to wasm. The run above is one.
02A testfrom the crate-level doc test
rustten seeds, network faults on
#[test]
fn server_accepts_under_chaos() -> Result<(), moonpool::SimulationError> {
    let report = SimulationBuilder::new()
        .processes(1, || Box::new(Server))
        .workload(Client)
        .enable_chaos([Chaos::Network(ChaosMode::Swarm)])
        .set_iterations(10)
        .run()?;
    assert_eq!(report.failed_runs, 0);
    Ok(())
}
rusta seed failed: replay it alone
SimulationBuilder::new()
    .set_debug_seeds(vec![failing_seed])
    .set_iterations(1)

Quick start: the whole file, how to run it and how to read the report.

03Your code and the providers
04See each technique work9 of 9 pages up
  1. One thread, one clock, one seedRun a seed twice and compare the two runs.
  2. Same code in production and simulationOne function, two sets of providers.
  3. Network faultsCut a link, clog it, close a connection.
  4. Storage faultsWhat a crash does to each sector after the last sync.
  5. RebootsA process starts again with fresh memory.
  6. Swarm testingEach seed draws its own set of faults.
  7. Assertions that must fireThe coverage fills seed after seed.
  8. Multiverse explorationThe run forks at each discovery.
  9. From a red seed to the bugReplay, then walk back to the first wrong event.

The Guide explains each technique in full. All the techniques.

In depth: moonpool-journal, byte by byte, moonpool-rpc, call by call. All the extras.

05Used by paros

paros, a journal service on Paxos, runs whole cells of machines on moonpool: the shipped daemon, on the simulated disk and network, with each fault family on. Its CI runs a sweep of seeds on each pull request.