# Testing

## Deterministic simulation

The simulation runs a whole cluster on one thread, with a virtual clock and an
order of events that a seed picks. The control plane, its API and its
controllers are the real code, and so is each node's agent. Only the hosts'
sockets, the cloud account and the client are fakes. A seed replays exactly,
so a failure found once runs again the same way until it is fixed.

For two virtual minutes, a client creates and deletes pods while the run
injects faults:

- Sockets close, or vanish with no close.
- Machines stall for up to 150 seconds.
- The cloud provider returns errors, a host restarts, and a Durable Object is
  evicted.
- SQLite fails as it does on a full or failing disk: a statement fails, a
  transaction rolls back, or a commit fails.

The faults then stop, and the cluster has 20 virtual minutes to settle. The run
fails when any of these happens:

- A request fails for a reason that no injected fault caused.
- A node turns NotReady too early, or stays Ready too long after its agent
  goes silent.
- A pod does not reach Running, or a deleted pod is still terminating.
- The pods a node runs differ from the pods bound to it.
- A watch ends with something other than what a LIST returns.

Other simulations cover the Raft group and the relays. The Raft simulation runs
real replicas, each on its own SQLite file. It drops, duplicates and delays
messages, cuts links, crashes members, some between applying an entry and
committing it, changes the group's members and hands leadership over.

Every pull request runs 256 seeds of each simulation, and a search runs new
seeds each day. Each run also counts its polls and SQL statements against a
budget, so a change that adds work to the control plane fails its pull request.

## Specs

Two designs are also written as TLA+ specs, and TLC, a model checker, checks
every state each one can reach:

| Spec  | What it models                                                                                                      | What it checks                                                                                               |
| ----- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Relay | A follower that holds node sockets for the leader, and the rows it builds their assignments from                    | A follower builds a node's assignment only from that node's rows, in the history its copy of the log follows |
| Copy  | Servers, or a cluster's Durable Object, that share one copy of the cluster in a bucket, with a lease and a takeover | One server writes at a time, and a takeover keeps every write the copy acknowledged                          |

- For each rule in the code that a property depends on, a check turns the rule
  off and confirms that TLC then finds the failure, so a spec that stopped
  checking anything would fail.
- Runs of the relay simulation are checked against the relay spec: each run
  must be a behaviour that the spec allows.
- A change to either spec runs the checks on its pull request.

## Real processes and real nodes

- **Server faults.** Two or three `kite-control` servers share one bucket while
  a test kills, stops and resumes them at random.
- **End to end.** A cluster runs pods on Linux nodes with containerd, under
  runc, gVisor and Kata, and the test drives it with kubectl.
- **Conformance.** The upstream Kubernetes conformance suite runs against both
  control planes. [Compatibility and limitations](/docs/reference/compatibility/) lists the
  specs that Kite declines, with the reason for each.
- **Scale.** Runs on AWS put 5,000 nodes and 150,000 pods on one cluster.
  [Scale and performance](/docs/scale/) has the results.

## Failure tests
(a table of faults, what was observed, and their status, drawn at https://runkite.io/docs/testing/)
