Checks: events and replay
Templates for the four events and replay stories. The hooks they assume are described in about the checks.
C-05: replay sends nothing
Section titled “C-05: replay sends nothing”- Proves: rebuilding a read model from history reproduces it exactly and sends no email, while live events during the rebuild are still handled once.
- Fails for: one handler that projects and sends. The replay that emailed every customer again.
- Harness needs: a fake mail sink; the ability to rebuild a projection into a new copy.
@Testvoid rebuildingTheOrderHistorySendsNothing() { eventLog.append(sampleOrders(500)); projections.catchUp("order-history"); var original = projections.snapshot("order-history"); mailSink.clear();
projections.rebuildInto("order-history", "order-history-v2");
assertThat(projections.snapshot("order-history-v2")).isEqualTo(original); assertThat(mailSink.messages()).isEmpty();}
@Testvoid aLiveOrderDuringTheRebuildGetsExactlyOneEmail() { eventLog.append(sampleOrders(500)); var rebuild = projections.rebuildIntoAsync("order-history", "order-history-v2"); pausePoints.await("rebuild-halfway");
var live = orders.place(NEW_ORDER); pausePoints.release("rebuild-halfway"); rebuild.join();
assertThat(mailSink.messagesAbout(live.id())).hasSize(1); assertThat(projections.contains("order-history-v2", live.id())).isTrue();}def test_rebuilding_the_order_history_sends_nothing(event_log, projections, mail_sink): event_log.append(sample_orders(500)) projections.catch_up("order-history") original = projections.snapshot("order-history") mail_sink.clear()
projections.rebuild_into("order-history", "order-history-v2")
assert projections.snapshot("order-history-v2") == original assert mail_sink.messages() == []A cheap structural guard to add next to it: fail the build if any handler registered as a projector depends on a mail, HTTP or message-publishing client.
C-06: meaning survives schema changes
Section titled “C-06: meaning survives schema changes”- Proves: a 30-second hold expires at 30 seconds in every supported producer and consumer pairing.
- Fails for: schema-only compatibility checks. The compatible schema that changed the meaning.
- Harness needs: the producer versions and consumer versions you support, runnable in one test.
static Stream<Arguments> pairings() { return SUPPORTED_PRODUCERS.stream() .flatMap(p -> SUPPORTED_CONSUMERS.stream().map(c -> Arguments.of(p, c)));}
@ParameterizedTest(name = "producer {0} -> consumer {1}")@MethodSource("pairings")void aThirtySecondHoldExpiresAtThirtySeconds(String producerVersion, String consumerVersion) { var heldAt = Instant.parse("2026-11-21T10:00:00Z"); var event = producers.version(producerVersion).seatHeld("S-1", heldAt, Duration.ofSeconds(30));
var expiresAt = consumers.version(consumerVersion).expiryOf(event);
assertThat(expiresAt).isEqualTo(heldAt.plusSeconds(30));}PAIRINGS = list(itertools.product(SUPPORTED_PRODUCERS, SUPPORTED_CONSUMERS))
@pytest.mark.parametrize("producer_version,consumer_version", PAIRINGS)def test_a_thirty_second_hold_expires_at_thirty_seconds( producer_version, consumer_version, producers, consumers): held_at = datetime(2026, 11, 21, 10, 0, tzinfo=timezone.utc) producer = producers.version(producer_version) event = producer.seat_held("S-1", held_at, timedelta(seconds=30))
expires_at = consumers.version(consumer_version).expiry_of(event)
assert expires_at == held_at + timedelta(seconds=30)The test asks the producer for a duration and the consumer for an instant, so neither side’s unit leaks into the test. That’s the point: the test states the meaning, and each side proves it honors it.
C-07: stale events can’t reopen a closed record
Section titled “C-07: stale events can’t reopen a closed record”- Proves: redriving an older event leaves a canceled order canceled, explains the skip, and still applies a genuinely missing event.
- Fails for: blind redrive. The dead-letter redrive that reopened a canceled order.
- Harness needs: deliver events to the consumer directly; read the redrive report.
@Testvoid redrivingAnOldCreateLeavesACanceledOrderClosed() { consumer.deliver(orderCanceled("O-1", 2)); var report = consumer.redrive(List.of(orderCreated("O-1", 1)));
assertThat(fulfillment.status("O-1")).isEqualTo(CANCELED); assertThat(fulfillment.pickList()).doesNotContain("O-1"); assertThat(report.skipped()).singleElement() .satisfies(s -> assertThat(s.reason()).contains("version 1", "version 2"));}
@Testvoid everyDeliveryOrderGivesTheSameFinalState() { var events = List.of(orderCreated("O-2", 1), orderUpdated("O-2", 2), orderCanceled("O-2", 3)); for (var permutation : permutations(events)) { fulfillment.reset(); permutation.forEach(consumer::deliver); assertThat(fulfillment.status("O-2")).as(permutation.toString()).isEqualTo(CANCELED); }}def test_redriving_an_old_create_leaves_a_canceled_order_closed(consumer, fulfillment): consumer.deliver(order_canceled("O-1", version=2)) report = consumer.redrive([order_created("O-1", version=1)])
assert fulfillment.status("O-1") == "canceled" assert "O-1" not in fulfillment.pick_list() assert len(report.skipped) == 1 and "version 1" in report.skipped[0].reason
def test_every_delivery_order_gives_the_same_final_state(consumer, fulfillment): events = [order_created("O-2", 1), order_updated("O-2", 2), order_canceled("O-2", 3)] for permutation in itertools.permutations(events): fulfillment.reset() for event in permutation: consumer.deliver(event) assert fulfillment.status("O-2") == "canceled", permutationC-08: the past is reproducible
Section titled “C-08: the past is reproducible”- Proves: rebuilding invoices after a rate change reproduces every issued invoice exactly, and an intentional recalculation produces separate, identifiable records.
- Fails for: looking up current configuration during replay. The replay that calculated a different invoice.
- Harness needs: a controllable rate table and clock.
@Testvoid rebuildingAfterARateChangeReproducesIssuedInvoices() { rates.set(DESTINATION, "0.0825", LocalDate.parse("2026-01-01")); clock.set("2026-03-10"); var issued = invoices.issueFor(shipOrder("O-3", "100.00"));
rates.set(DESTINATION, "0.0850", LocalDate.parse("2026-07-01")); clock.set("2026-09-01"); projections.rebuild("invoices");
assertThat(invoices.get(issued.id()).contentHash()).isEqualTo(issued.contentHash()); assertThat(invoices.get(issued.id()).total()).isEqualByComparingTo("108.25");}
@Testvoid aRecalculationIsRecordedSeparately() { var issued = invoices.issueFor(shipOrder("O-4", "100.00")); var adjustment = invoices.recalculate(issued.id(), "0.0800", "rate correction");
assertThat(invoices.get(issued.id()).contentHash()).isEqualTo(issued.contentHash()); assertThat(adjustment.references()).isEqualTo(issued.id());}def test_rebuilding_after_a_rate_change_reproduces_issued_invoices(rates, clock, invoices, projections): rates.set(DESTINATION, Decimal("0.0825"), effective=date(2026, 1, 1)) clock.set(date(2026, 3, 10)) issued = invoices.issue_for(ship_order("O-3", Decimal("100.00")))
rates.set(DESTINATION, Decimal("0.0850"), effective=date(2026, 7, 1)) clock.set(date(2026, 9, 1)) projections.rebuild("invoices")
rebuilt = invoices.get(issued.id) assert rebuilt.content_hash == issued.content_hash assert rebuilt.total == Decimal("108.25")Related pages
Section titled “Related pages”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.