Unit 7 of 15 · about 4 hours · implement

Property-based state-machine testing with crash and restart, and deterministic schedule replay

TLC checks a model; property tests check the code. The Programming unit on property, metamorphic and differential testing with shrinking built a DatabaseComparison machine, and the Systems unit on distributed histories and deterministic failure simulation built a seeded fault scheduler. Here the new work is crash and restart with durable versus volatile state, and shrinking a distributed failure.

You'll be able to

  • Extend a RuleBasedStateMachine for your log with crash and restart rules that separate durable from volatile state, checked against a reference model.
  • Plant a nontrivial recovery or ownership bug, keep the shrunk failing program, and explain what the shrinker removed.
  • Replay a failing schedule from its saved schedule and seed, and state which nondeterminism your harness does not control.

Covers

Property-based state-machine testingDeterministic schedule exploration
1

Read

In this order, only the parts listed

0 of 4 done

  1. Rule-based state machinesHypothesis - Stateful Testing

    The consumes, precondition and invariant sections, with the DatabaseComparison machine and its shrinking example as review (page read 2026-10-15)

    Review the machine you built for the Programming unit; read the sections on consumes, preconditions and invariants closely.

  2. Test settings for state machinesHypothesis - Stateful Testing

    The TestCase.settings = settings(max_examples=50, stateful_step_count=100) example: fewer examples with longer programs when hunting ordering bugs

  3. Simulation testing sectionFoundationDB: A Distributed Unbundled Transactional Key Value Store (Zhou et al., 2021)

    The deterministic simulation framework: single-threaded deterministic execution, fault injection and seed replay as the model for your own scheduler

    Read as design to copy at learner scale, not as code to import. A seeded fault injector around ordinary local processes is fault injection, not deterministic simulation, unless your harness controls every source of nondeterminism.

  4. Chapter 9: Formal Methods and Randomized TestingDDIA 2e - Chapters 9, 10 and 14 Review

    Printed pp. 384-387: property-based testing, fuzzing and deterministic simulation testing as the empirical half beside proofs, and why model and implementation can drift apart

2

Focus on

  • Bundles build the universe of values rules share. Generating fresh keys per rule rarely collides; drawing from a bundle forces the overwrites and deletes that find bugs.
  • The invariant runs after every step. It compares system against model on the same operation history, so the first failing step is already localized.
  • Shrinking deletes what does not matter. The docs' five-step program (new key, new value, save, delete, check) is the minimal story: keep it, it is the regression test.
  • A seed replays a run only when the harness controls every source of nondeterminism and the code, inputs and configuration are fixed. Save the generated schedule and the shrunk failing test with the seed.
Common mistakes · 3
  • Confusing rule assertions with invariants. Use rule assertions for operation-specific results and invariants for properties that hold after every step; both cover only the generated executions, not every interleaving.
  • Using assume to skip inapplicable states. Sparse assumptions starve the generator; precondition filters rules before generation instead.
  • Keeping the passing run and deleting the planted-bug demo. The bug demo is what proves the machine can catch its fault class.
3

Try it yourself

Closed-book, before checking anything

Closed-book, add crash and restart rules to a key-value log machine that keeps durable and volatile state apart, with an invariant that every acknowledged durable write survives restart. Plant a bug that drops an acknowledged write on restart and paste the shrunk failing program.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why do the docs use Bundles for keys and values instead of generating fresh ones per rule?Answer

    Bundles build a shared universe, so later rules reuse earlier values. Fresh generation rarely collides, which hides the overwrite and delete interactions that find bugs.

  2. 2.What does the shrinker output for the planted restart bug, and why keep it?Answer

    The shortest program that still loses an acknowledged write: the few writes, the crash and the restart that matter. It is the regression test: short, deterministic and readable.

  3. 3.When should stateful_step_count go up and max_examples go down?Answer

    When hunting ordering bugs that need long setups: longer programs per example, fewer examples overall. The docs' example doubles steps to 100 and halves examples to 50.

  4. 4.A seeded schedule fails once and passes on rerun with a new seed. What do you keep?Answer

    The failing seed, the full generated schedule and the shrunk failing test, with code and configuration versions. A seed alone replays only if the harness controls every source of nondeterminism.

5

Practice

You're done when

Your machine passes clean, catches a planted recovery bug with a shrunk program you can explain line by line, and a failing schedule replays from its saved schedule and seed.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 12 more in the section
  • Hypothesis - Stateful TestingHypothesis · required

    Use RuleBasedStateMachine against a reference model for property-based state-machine tests of your extension, keep the failing seeds and shrunk examples, and plant a bug to show the machine detects it.

  • FoundationDB: A Distributed Unbundled Transactional Key Value Store (Zhou et al., 2021)FoundationDB · support

    Read the simulation-testing section (deterministic single-threaded simulation, fault injection, seed replay) as the model for your own scheduler, and the architecture for unbundled transactions.

  • DDIA 2e - Chapters 9, 10 and 14 ReviewMartin Kleppmann and Chris Riccomini · required

    Revisit uncertainty, consistency, consensus and responsible system design while extracting the final contract. Use the book to challenge assumptions and alternatives, not to replace executable evidence.

Also in this section

  • TLA+ Video CourseLeslie Lamport · primary

    Complete lectures 1 to 10 (lectures 8, 9 and 10 have two parts each) and check the corrections page, while specifying a reduced transaction, workflow or replicated-log model from the capstone. Run TLC after every extension, report the model bounds with every result, and retain the first meaningful counterexample rather than polishing only the final model.

  • TLA+ ExamplesTLA+ Foundation · support

    Check specifications/transaction_commit/ (TCommit.tla, TwoPhase.tla, PaxosCommit.tla with their .cfg files) with TLC alongside the lectures, and read the Paxos specifications for depth. specifications/TwoPhase/ is a hardware handshake, not transaction commit.

  • Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - CRDTs and CollaborationUniversity of Cambridge (Martin Kleppmann) · support

    Use Section 8.1 (operation-based and state-based CRDTs, operational transformation) for the CRDT unit, and work Exercise 21 (prove the operation-based map CRDT converges) and Exercise 22 (its multi-value variant).

  • A Comprehensive Study of Convergent and Commutative Replicated Data Types (Shapiro et al., 2011)INRIA report (Berkeley course copy) · support

    Read Sections 1 to 3 (state-based and operation-based definitions, the semilattice and delivery conditions) and one example type for your implementation, not the whole catalog.

  • Learn TLA+Hillel Wayne · support

    Use the core lessons and the examples as a second explanation when a lecture stalls, and as the PlusCal reference if you write algorithms rather than raw actions.

  • MIT 6.5840 - Verification Lecture and Final ProjectMIT PDOS · required

    Study the Spring 2026 verification lecture and IronFleet reading, then use the final-project guidance to frame a bounded real-system extension, evaluation and report. Course grading and staff review are unavailable to self-study, so use the roadmap defense rubric.

  • Jepsen - Consistency Models and AnalysesJepsen · required

    Use the framework's generator, client, nemesis and checker roles to design the campaign, Knossos for single-register linearizability and Elle for transactional anomalies on recorded histories, and the public analyses for fault models. A simplified local checker must declare its object, model and completeness limits.

  • Elle: Inferring Isolation Anomalies from Experimental Observations (Kingsbury and Alvaro)arXiv · required

    Read how Elle infers version orders from list-append and register histories and detects cycles for G0 to G2. It needs complete histories, and a clean run is not a proof of serializability.

  • How Amazon Web Services Uses Formal Methods (Newcombe et al., 2015)Amazon Science · support

    Read it for why industrial teams specify designs in TLA+ and which bugs model checking found that testing missed. Its effort figures are anecdotes, not benchmarks.

  • HLD Handbook - CRDTs, Multi-Region and Architecture Trade-offsHLD Handbook · support

    Read the CRDT, multi-region, distributed SQL and relevant case-study chapters only after the formal core passes. Use its design prompts to prepare the final comparison and defense.

  • CMU 15-721 - Selected Advanced Database Systems UnitsCarnegie Mellon Database Group · depth

    Select at most one lecture group that informs your extension: #02 and #03 (data formats and encoding), #08 (scheduling and coordination) or #17 to #22 (system analyses such as BigQuery, Databricks, Snowflake, DuckDB and Redshift), with their papers. The course project needs a group, cloud credits and staff sign-off, so there is no runnable self-study project.

  • Replicated Log and Stream Processor - Final CapstoneRoadmap-Final · support

    Finish the protocol and invariant specification, deterministic fault campaign, bounded real-code extension, fallback, ablations, workload regions, negative result, operations dossier and independent reproduction package.