Executable checks for correctness, concurrency, and recovery.
Executable checks for correctness, concurrency, and recovery. Each check states its expected outcome so that results can be validated automatically.
Correctness
-- A created order has a matching audit eventSELECT count(*) FROM orders o WHERE NOT EXISTS (SELECT 1 FROM order_events e WHERE e.order_id=o.id);-- Expected: 0
Concurrency: no overselling
Run N concurrent buyers against a SKU with available = 1.
SELECT available FROM inventory WHERE sku='SKU-HOT';-- Expected: 0 (exactly one buyer wins; the rest get OUT_OF_STOCK)SELECT count(*) FROM reservations WHERE sku='SKU-HOT';-- Expected: 1
Idempotency: retried create
Send the same Idempotency-Key twice.
SELECT count(*) FROM orders WHERE customer_id=$c AND created_at > now()-INTERVAL '1m';-- Expected: 1 (second call returns the first order, creates nothing)
Duplicate callback
Deliver the same payment callback twice.
SELECT count(*) FROM payment_events WHERE provider_event_id=$eid;-- Expected: 1 (second delivery is a no-op; no double capture)
Recovery: partial external failure
Simulate capture failing after reservation.
-- Expected: a compensation event releases the reservation; inventory returns to prior levelSELECT to_state FROM order_events WHERE order_id=$o ORDER BY seq DESC LIMIT 1;-- Expected: 'cancelled' (or reservation released)