Test, migrate, and operate

Test object boundaries and lifecycle

Use the Workers Vitest pool to call typed stubs, inspect isolated storage, trigger alarms, and prove sharding.

8 minute lesson

~~~

Durable Object tests should run in the Workers runtime with configured bindings. Call RPC through stubs for normal behavior, then use Cloudflare test helpers when storage or alarm internals need direct evidence.

Test two object names for isolation, concurrent calls for invariants, restart or hibernation behavior, alarm retries, and unauthorized routing. Each test should begin with isolated storage.

Write one direct RPC test and one full Worker request test for the same room action.

Test behavior, not only HTTP status codes:

same room: writes are observed in order
different room: state is isolated
restart: durable state remains
duplicate request: effect is not duplicated

Add an alarm or WebSocket case only after the storage boundary passes. A local single-request test cannot prove coordination. Run concurrent clients and include one failure between receiving a request and completing its external side effect.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →