Diffinery

homeflare/celldpublic

celld/docs/testing.md
142 lines · 7.6 KBRaw History
1# Testing
2
3celld makes three important promises:
4
5- An acknowledged write is durable.
6- A cell has one writer at a time. It never has two.
7- Code written for Cloudflare Workers and Durable Objects operates the
8 same on celld.
9
10We try to break each promise at the layer where a failure shows most
11clearly. We test the API contract with differential execution against the
12Cloudflare runtime. We test the coordination protocol with deterministic
13simulation. We test the full system with fault injection on live fleets.
14
15## Conformance: two runtimes, one output
16
17We test the compatibility promise differentially. We run each Workers and
18Durable Objects program twice: once on workerd, the runtime binary that
19Cloudflare operates in production, and once on celld, on identical bytes.
20The two outputs must be equal. This shows two facts at once: the program
21is real Cloudflare code, because workerd accepts it, and celld obeys the
22contract, because the outputs are equal. A test cannot agree with our own
23runtime by accident.
24
25The corpus only grows. When celld gets a new API surface, we add fixtures
26for that surface, and the fixtures must give equal output on the two
27engines. We also port test suites from workerd itself: the Durable
28Objects contract, the web-platform globals, and the upstream Web Platform
29Tests. Before a release, we also replay scenarios through the full
30`celld` binary in each deployment mode: storage, SQL, alarms, streams,
31WebSockets, and lifecycle.
32
33## Simulation: the protocol under adversarial schedules
34
35The dangerous bugs live in the coordination: a crash during an ownership
36handoff, a lease renewal that races a takeover, an alarm that fires
37against a partially restored cell. These windows are nanoseconds wide and
38open rarely, so a test cannot wait for them.
39
40Thus the coordination protocol is a
41[pure decision core](https://github.com/denoland/celld/tree/main/crates/logic)
42with no I/O of its own: the clock, the randomness, and the object store
43are interfaces, and a simulator drives the core. The simulated store
44injects latency, compare-and-swap races, and lost responses; the clocks
45drift apart; a node can crash at each await point. Scripted adversaries
46play the cells: a handler that never returns, a write stream that stops
47halfway. V8 stays out of the simulation, because V8 is not deterministic.
48
49A seeded scheduler drives each run, so a failure is not a fluke: the seed
50replays it exactly, every time, and we keep the seed until the bug is
51dead. We examine each property for safety (two writers in one epoch, a
52lost acknowledged write, an expired lease that comes back) and for
53liveness (each armed alarm fires, and ownership settles on one node after
54a crash). A property must survive tens of thousands of seeds, and the
55core protocols have run through millions of different schedules.
56
57Simulation has a known failure mode: the checker that cannot fail. Thus
58we also test the checkers: we run deliberately broken variants of the
59protocol against the properties, and the properties must find the damage.
60A suite that stays green against a broken protocol is a broken suite.
61
62## Live fleets: what simulation cannot see
63
64Simulation cannot see the real S3 tail latency, the real kernel and
65filesystem behavior, or V8 under memory pressure. The third layer is
66therefore a permanent fleet lab: standard VMs from standard providers,
67and a real bucket. The workloads rotate: chat rooms under many WebSocket
68connections, working sets that shift across tens of thousands of cells
69(each cell has a unique checksum), deployment cutovers under load, and
70runs that fill the nodes to the memory limit. The lab qualifies each
71release, and between releases it pushes the density and the fault
72coverage further. Each run makes an archived evidence bundle: the
73configuration, the verification sweeps, the node journals, the kernel
74logs, and the phase timings. We keep a red run with the same care as a
75green run, because a failure that the harness caught is a result, not a
76retry.
77
78We inject the faults between verification passes. A pass fetches each
79cell through different nodes and compares the durable state exactly: the
80status, the body, and the full message ledger. Each run therefore has a
81clean picture before the fault and after it. A cell can be unavailable
82for a short time while its ownership moves, but its committed state must
83stay complete, and a live node must serve that state again.
84
85The scenarios attack every seam that we know. We stop a node with
86`SIGKILL` in the middle of a write stream and delete its local database,
87so the recovery can only come from the bucket: every acknowledged write
88comes back, because the output gate held each response until the write
89was durable. We freeze an owner node, write to its cells through other
90nodes, and unfreeze it: the node sees that its lease moved and refuses to
91serve the old state, and each write from the other nodes lands exactly
92one time. One epoch has at most one writer. We cut a node off from the
93bucket, and it fences itself, because a node that cannot replicate must
94not own cells. We throttle the bucket, so it answers each request with a
95429: the engine slows to the write rate of the store and does not amplify
96the throttle, because a node that knows its replicated position does not
97ask a slow store for extra listings. We stop a full host at the provider
98level in the middle of a workload: its cells move to the other nodes, and
99when the host returns, it joins again with no duplicate residency. Across
100every run of every scenario, no acknowledged write was lost and no
101committed state was damaged; the verification sweeps show zero body
102faults, zero status faults, and zero lost messages.
103
104## A few numbers we trust
105
106Each number includes the condition of its measurement. A number without
107its conditions has no value.
108
109- **The epoch fence holds under contention.** Five hundred claimants
110 tried at the same time to own the same cells: 5,500 attempts, one
111 writer for each epoch, zero violations.
112- **A warm resident request is local.** A request to a resident cell does
113 zero bucket operations and returns in p50 ~1.1 ms and p99 ~7 ms (a
114 fixed-host measurement). Only a cold activation touches object storage.
115- **A durable write costs one bucket round trip.** The response waits
116 until the write is in the bucket; that is the meaning of RPO=0, and the
117 storage round trip is therefore the minimum latency for one write.
118 Concurrent writes to one cell join one shared upload, so the throughput
119 of one cell is not one round trip for each write.
120- **Restores are fast.** A 62 MB cell restores from the bucket in 1.35 s,
121 and placement handles a restore as normal work, not as an emergency
122 procedure.
123- **Ten small nodes held real scale.** A fleet of ten nodes, each with 4
124 vCPU and 8 GB, held 10,000 resident cells and 20,000 concurrent
125 WebSocket connections. We stopped two of the ten nodes, and the data of
126 every cell was available again on another node in ~11 s at the tail
127 (with reserve headroom).
128
129## The failure edges we intend to find
130
131We must also know where a policy stops, so we record the edges instead of
132tuning them away. The clearest edge is the reserve headroom: a fleet that
133is full to its resident limit has no space for the cells of a lost node,
134so a failure of more than one node at the limit degrades the service,
135and a fleet with headroom does not. We measure both sides of that line,
136the good restoration with reserve and the red case without, because this
137measurement is part of the work.
138
139If you find an edge that we did not find, tell us: a schedule that breaks
140a promise, a fault that we did not inject, a number that you cannot
141reproduce. That is exactly the bug report that we want:
142[github.com/denoland/celld/issues](https://github.com/denoland/celld/issues).