CoursesBackend engineering from first request to production
Puzzle 2 · 3 of 18
Can two clients prove the rule?
Test a retry through the running service and read what survived.
All puzzles in this course
The problem
A test double standing in for the database can return success without writing anything. How would a reviewer know your server actually preserved the bookmark?
See it
Scroll sideways to see the full diagram.
Two workers submit river.
Step 1 of 4The database admits one new row.
Step 2 of 4A fresh process opens the same file.
Step 3 of 4The test checks the actual list.
Step 4 of 4
The building block
An integration test checks several real components together. Here the client, server and database all run. Run the supplied test. It creates an empty database, starts the server and sends two writes with the same name from separate workers. It expects one creation and one existing result in either order. It stops the process, starts another against the same file and reads back the list. This distinguishes a durable write from a value held only in memory. Two workers exercise contention without proving correctness for every possible ordering. The unique key provides the underlying guarantee.
Design a test that catches a believable bug
Suppose deletion removes river from a process's working copy and replies 204. An immediate read sees an empty list. An implementation that forgot to change the database passes both checks. Restart the process against the same database and read again: river reappears. Now try the correct implementation and predict the second delete. The row remains absent and the fixture returns 404. Record responses and final rows separately. A test that recreates the database between the two processes also loses the evidence it meant to inspect.
Try it
Optional local lab
Complete the deletion assignment in the lab. Show that removing the row survives a restart and that a second delete follows your documented contract.
Check yourself
Sources
What you now know
An integration test can check replies, stored state and persistence across a fresh process.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.