moonpool ~
GitHub →
$ techniques

Assertions that must fire

A fault that never fires tests nothing. The coverage fills seed after seed, and a hole fails the run.

The problem

A test that passes a thousand seeds says nothing about a path that no seed took. The retry after a lost reply, the read that sees two versions, the check of a damaged frame: if no run reached them, they are not tested. A green run cannot tell you this.

The technique

Two kinds of assertions. assert_always! is an invariant: it must hold each time, and one failure fails the seed. assert_sometimes! and assert_reachable! are coverage: each one must fire in at least one seed of the run. The runner counts them across the seeds.

With UntilCoverageStable, the default, the runner runs seeds until each coverage assertion has fired and the coverage stops growing (by default, 10 seeds in a row with nothing new, and at most 1000 seeds). An assertion that never fired is in the report (coverage_violations), and the run fails. A run that hits the cap before the coverage is stable fails too.

The live run

The register has 5 coverage checks. This run removes the bit_flip network family, so no frame is ever damaged: one check can never fire. The checks turn green at their first hit; the last one stays red, and the run stops at its cap of 120 seeds and fails. Put bit_flip back and run again: in this register, a flipped bit is rare, so the check fires late.

the coverage checks of the register

The code

The check that no seed reaches here. Only a flipped bit makes a frame fail its check word:

let Some(request) = Frame::decode(&bytes) else {
    // A flipped bit: the check word does not match. Only the
    // bit_flip network family reaches this line.
    assert_reachable!("a server drops a damaged frame");
    continue;
};

A coverage check on the client, and the invariant that the planted bug breaks:

assert_sometimes!(oldest < seen, "a read sees two versions");
assert_always!(fresh, "a read returns the last committed write");

In the Guide

All the techniques