Skip to content

Latest commit

 

History

History
151 lines (130 loc) · 8.85 KB

testing.md

File metadata and controls

151 lines (130 loc) · 8.85 KB

Testing

make check runs everything that needs no Docker: code generation checks, lint, the Go tests under the race detector, the Python tests, and the coverage floors. CI runs the same targets on every pull request, split into six jobs (CI); make ci-report posts the VM's run as a commit status when no hosted service is available (ADR 0014). The other kinds of test below are run by hand or by their own target, and CI runs none of the rows marked "no" (Docker, S3, extended chaos, fuzz, flaky, benchmarks).

Kind Command In make check Where
Unit cd go && go test ./..., cd python && python -m pytest yes next to each package
File format, the same bytes in Go and Python go test ./internal/formats/kv, python -m pytest tests/test_kv.py tests/test_kv_block_shapes.py yes testdata/format/, TestCompressedBlockShapes
Golden output, Go against Python go test ./cmd/mr -run TestExamples yes testdata/examples/, #153
Cluster in one process go test ./internal/worker yes internal/worker/cluster_test.go
Chaos, seeded go test ./internal/worker -run TestChaos -chaos.runs=50 3 seeds TestChaos, TestChaosPrograms (#155)
Coordinator model go test ./internal/coordinator -run TestModel -model.runs=300 15 seeds model_test.go (#154)
Processes on localhost, with a SIGKILLed worker and coordinator go test ./internal/e2e yes #151
Python coordinator, Go workers make py-e2e yes, but they skip if Go cannot build them; make py-e2e, run by CI's go job, sets MR_REQUIRE_GO, so a skip fails python/tests/test_coordinator_e2e.py, #36
Storage contract go test ./internal/storage yes; make e2e-s3 adds a real gateway #156
Fuzz make fuzz (FUZZTIME, default 20s a target) stored seeds only #152
Flaky tests make flaky no #157
Mutation make mutate no go/tools/mutate, #161
Compose cluster make e2e, make e2e-s3, make chaos no scripts/e2e.sh, scripts/chaos.sh
Benchmarks make perf against bench/baseline.txt no #160, bench/README.md
Memory and size limits go test ./internal/extsort ./internal/task ./internal/formats/kv yes; the two 80 MB heap measurements run without the race detector only (ADR 0025) #160
Documentation against configuration make docs-test yes, in make lint docs/tests, ADR 0025
Names in the guides (make targets, paths, ADRs, scripts, skills) and the CHANGELOG's layout and citations make docs-test yes, in make lint docs/tests/test_references.py, docs/tests/test_changelog.py

A failing seeded test names its seed; -chaos.seed=N -chaos.runs=1 or -model.seed=N -model.runs=1 makes the same choices again.

Coverage

make check fails if a package's statement coverage falls under its floor in go/cover-floors.txt or python/cover-floors.txt (scripts/cover.py). A Go package's coverage counts every test in the module and the commands that internal/e2e builds and runs, not only its own tests; a package with no floor fails too, so a new one must be given one. Each floor is one point under the value measured when it was set, rounded down. make cover runs the tests and prints each package's coverage beside its floor.

Measured on 2026-11-07:

  • Go (measured again on 2026-11-12): 92.0% of 3,315 statements in 31 checked packages. The lowest are tools/mutate (28.7%; the rest of it runs go test on each mutant, in make mutate), then internal/wal (86.9%), cmd/mr (88.2%), cmd/worker (88.5%) and examples/invertedindex (89.5%). Unchecked: the generated protobuf code, the S3 test server, examples/internal/run (a test helper) and examples/wordcount, which the cluster, local and golden tests run as their reference.
  • Python (measured again on 2026-11-16): 99.7% of 2,288 statements in 5 checked packages, the generated protobuf code left out. The value depends on the host: four of the seven lines missed are the IPv6 listener in coordinator/statusweb.py, which test_serve_ipv6 reaches only on a host with an IPv6 loopback address, such as the course VM (99.9% there). The other three are two guards in the status page's timeline for an attempt with no time window, and the coordinator dropping a job's oldest attempt once it holds MAX_ATTEMPTS. tests/test_edges.py covers the last error paths: the MRKV writer's MAX_BLOCK_SIZE checks, a bad Snappy length prefix, a write that accepts no bytes, and others.

Statement coverage says that a line ran, not that a test would fail if the line were wrong. Mutation testing measures that.

Mutation testing

make mutate runs go/tools/mutate over the critical Go packages. It changes one operator, constant or boolean at a time, runs the package's tests on each change through go test -overlay (the tree is not modified), and prints the changes no test caught. A mutant that survives is either a missing test or a change that makes no difference. It takes several minutes a package; run it on the VM.

Measured on 2026-11-07:

Package, files Killed Survived Score
internal/partition, hash.go 7 0 100%
internal/extsort, merge.go sorter.go 71 5 93.4%
internal/coordinator, tasktable.go 171 15 91.9%
internal/task, task.go 62 6 91.2%

The first run, on 2026-10-28, left 36 survivors (77.6% to 89.8%), and tests were added until 13 were left, which were judged to make no difference that a test could see. Their counterparts are listed first; one of them, the sort budget, is observable and is listed with the missing tests. The other missing tests are in code added since, which the tests pin less tightly: the progress reports that task.go sends and LATE speculation in tasktable.go (ADR 0019).

Survivors that make no difference a test could see:

  • extsort: the tuning constants DefaultBudget and recordOverhead (sorter.go:30,33); s.arena[:1] for s.arena[:0] after a spill (sorter.go:182), since a record's offset is the arena's length; and index <= index for < in the merge's tie break (merge.go:61), since no two streams share an index.
  • coordinator/tasktable.go: -2 for the -1 that means "none yet" (lines 114, 209 and 274), and a starting best rank of 1 (274), which the first candidate overwrites; stopped := true (619), which matters only for a task in progress with no attempt, a state the table never leaves a task in.
  • task/task.go: writeKV's size on an error (lines 241, 247, 251), which its caller discards.

Survivors that mark a missing test:

  • coordinator/tasktable.go, in LATE speculation: the mean of a worker's task speeds (88), the checks on a running attempt's age and progress (196, 199, 200, 201), the percentile used for "slow" (247, 254), and the speed recorded when an attempt ends (379, 396).
  • task/task.go: the condition under which a map task reports its progress (129), and each partition's sort budget, DefaultBudget * R for / R (100). The mutant changes memory use, and also when a map task spills: with R = 2 and two partitions, a partition holding 40 MiB spills under the real 32 MiB budget but not under the mutant's 128 MiB.

make mutate-py does the same for the Python MRKV format and partition function with mutmut, installed by pip install -e 'python[dev,mutation]'; python/pyproject.toml names the files and the tests it runs. It takes about a minute.

File Killed Survived Score
formats/kv.py 372 77 82.9%
partition/hash.py 11 3 78.6%

The first run killed 78.4% of kv.py. tests/test_kv_boundaries.py now kills the rest of the mutants that a test could see, at limits no test had reached: a length of exactly 128, a record, a block and a declared size of exactly MAX_BLOCK_SIZE, a three-byte snappy prefix, and a length prefix cut off at the end of a block. The one timeout, counted as killed, is a length encoder made to loop forever. The 80 survivors in the two files are of three kinds:

  • 47 change only the text of an error message. Tests check an error's kind, not its wording.
  • 18 change the CRC-32C table, which is built when the module is imported, before mutmut switches a mutant on. The test vectors written by the Go code catch them: making the table's inner loop run 9 times instead of 8 fails tests/test_kv.py.
  • 15 make no difference: a value replaced by another that is just as false (None for False, "" for None); zstd's module-level compress for a ZstdCompressor, which writes the same frame; f.read(2) for f.read(1) at the end of the file; and changes that turn one bad block into another (a zstd frame that declares 0 bytes; an 11th byte of a length prefix; _field's check for a length of 2^64 or more, which the check against the payload's end covers).