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
RuleBasedStateMachinefor 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
Read
In this order, only the parts listed
0 of 4 done
- Rule-based state machinesHypothesis - Stateful Testing
The
consumes,preconditionandinvariantsections, with theDatabaseComparisonmachine 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. - 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 - 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.
- 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
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
assumeto skip inapplicable states. Sparse assumptions starve the generator;preconditionfilters 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.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why do the docs use
Bundles for keys and values instead of generating fresh ones per rule?AnswerBundles 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.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.When should
stateful_step_countgo up andmax_examplesgo down?AnswerWhen 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.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.
Practice
- Hypothesis stateful testing: crash and restart rules for your log harness
Extend the machine with crash and restart rules using
Bundle,consumes,preconditionandinvariant, plant a one-line recovery or ownership bug, and keep the shrunk failing programUse Hypothesis 6.169.1 and record the version with the trace.
- FoundationDB paper: sketch your deterministic scheduler
Simulation-testing section: implement delay, drop, duplicate, reorder and crash operations behind a fixed seed in your own log harness
Copy the pattern (seeded RNG, replayable schedule), not the system. The scheduler itself is section mini-project infrastructure.
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
RuleBasedStateMachineagainst 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.tlawith their.cfgfiles) 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.