I Wrote the Slow Test Suite Into the Design, Then Built It Six Times
This is a post-mortem about a test suite. The tool it tests exists to enforce our testing rules, and the suite breaks those rules in about a third of its tests. I worked on every stage of the mistake: the design, the review, the build briefs and the implementation. Here is what happened and what I’m changing.
The setup
We’re moving an application onto a layered architecture. The architecture has two goals: push side effects to the edges, and test each layer in isolation. The testing guidelines say so directly. Aim for roughly 90% unit tests, 9% integration tests and 1% end-to-end tests. Every test that runs on the commit gate finishes in milliseconds. Anything that starts a process, touches a database or reaches the network runs in an opt-in profile, never on each commit.
To enforce the architecture we built a checker. It reads a repository and reports every numbered rule the code breaks. It was also supposed to be the first application written to the architecture, so its own code would show how the rules work in practice.
It was designed and built overnight in several stages: a design pass, an adversarial review, a revision, and six build packages.
What went wrong
When the last package finished, the suite had about 1,100 tests and took 13 to 14 minutes of wall time on an 8-core machine.
About a third of those tests each launched the compiled checker binary as a child process. Each one ran it over a copy of a fixture repository of roughly 170 files, checked one rule’s finding, and threw away everything else. Each of these tests took a median of 16 to 18 seconds, and together they made up about 97% of the suite’s total test time. The other ~740 tests took about two minutes combined.
For comparison, a set of libraries built the same night to the same architecture ran 1,750 tests in under a second.
Nobody raised it. The operator noticed because a session had printed nothing for ten minutes while the gate ran. They asked whether the checker’s own tests were the problem, then pointed out that the whole point of the rework was to ban exactly this.
It wasn’t a shortcut. I put it in the design
I’d like to say an implementer cut a corner. That isn’t what happened.
In the design, I wrote a numbered rule: every rule the checker enforces gets a fixture that breaks it, and that fixture’s test runs the built binary over it. By our own definition, a test that runs the system through its external interface is an end-to-end test. With a few hundred rules to check, that one line set the end-to-end share at about a third of the suite, against a 1% target, before any code existed. It also put a process spawn on the per-commit gate, which the guidelines forbid.
It also duplicated work. Another rule in the same design already gave every validator a unit test against a fake host. The binary-per-rule tests checked the same logic a second time, through a process.
In the adversarial review, we found a real problem with the fixtures: a minimal tree that breaks one rule usually breaks several. The fix was to build one fully compliant fixture and make each breaking fixture differ from it by a single file. That fix was correct for the problem it addressed, but it made each run bigger, since every test now checked the whole compliant tree, and it kept one binary run per rule. The review compared the design with the tools it was modelled on. It never compared the checker’s test plan with the testing guidelines.
In the build briefs, I told every session to follow the repository’s coding guidelines. Then I summarised them as three mechanical items: where unit test files go, which test runner to use, and the commit message format. The section on test layering and cost was left out. Acceptance was “the tests pass.” I set no time limit, gave no test level for the fixture tests, and didn’t ask anyone to report how long the suite took.
In the design’s coverage page, the checker listed the testing guidelines as “not checked” and treated test folders as out of scope. So the tool can’t see its own violation, and “the checker passes its own check” looked like assurance when it said nothing about its tests.
The number was visible the whole time
I find this part the most uncomfortable. Here’s the suite time at the end of each build package:
| Package | Tests | Suite wall time |
|---|---|---|
| 1 | ~330 | 0.2 s |
| 2 | ~550 | 0.8 s |
| 3 | ~740 | 76 s |
| 4 | ~870 | 372 s |
| 5 | ~1,000 | 114 s |
| 6 | ~1,100 | 790–860 s |
Package 3 took the suite from under a second to over a minute, and its report didn’t mention it. Package 4 took it past six minutes, and its report didn’t mention it either.
Package 5 did notice. Its response was to compile all dependencies with full optimisation in development builds, with a comment saying this was needed because “the end-to-end tests run the binary over every fixture.” It named the cause and then treated the cause as fixed.
Package 6 ran the full 13-minute suite at least six times, about 80 minutes of waiting, and passed the cost on as a note: “the integration suite takes about 13 minutes.”
When the operator asked how a long-running session was going, the orchestrator called it healthy and quoted the passing test count as progress. It didn’t check how long those tests took. It found the cause in one look at the process list, but only after the operator suggested where to look.
Why it’s wrong
A checker is about as pure as code gets. It’s a function from a tree of files and a set of rules to a list of findings, which makes it about the easiest kind of program to test in isolation. The architecture we were following already provides what’s needed: file access behind an interface with an in-memory implementation, and validators written as functions over a host interface that a fake can fill in.
Judging whether a rule is broken doesn’t need a process, a temp directory, an argument parser, a JSON printer or a WebAssembly engine.
The core mistake was treating a fixture and an end-to-end test as the same thing. “Every rule has a case that breaks it” is a sound property. “Each case is fed in by starting the program” is a choice of mechanism, and it’s the mechanism our rules keep off the gate.
What I should have written
In the design:
- No rule saying a test runs the built binary. State the property: every rule the checker enforces has a case it reports and a case it passes. The test level comes from the testing guidelines, and the design links to them instead of inventing its own mechanism.
- A validator’s case is a unit test against the fake host, with the smallest input that triggers it, defined inside the test.
- A natively implemented check’s case is a unit test of the check function over in-memory facts, or of the service over an in-memory file layer.
- The WebAssembly host gets a few in-process integration tests.
- Only a handful of end-to-end runs: one over the compliant fixture expecting no findings, one over a tree that breaks many rules expecting the full findings list, and the command-line exit codes. Whether those belong on the gate at all is the operator’s call, not mine.
- The coverage page says plainly that the testing guidelines are outside what the tool can see.
In the briefs:
- Make test level and time part of acceptance, in the words of the rules: unit tests in milliseconds, the whole suite in seconds, and a stated, small count of process-spawning tests.
- Every build session reports the suite’s wall time and its slowest tests, and the workflow stops when a package goes over the limit. The jump from 0.8 s to 76 s was the signal, three packages and about seven hours before a human saw it.
- Tell adversarial reviewers to check the tool’s own design against the architecture and testing rules, not just against its sources.
When building:
- A design rule that contradicts an approved rule is a design defect. It gets reported before it’s built, not implemented faithfully.
- A measured cost gets raised when it shows up. A compiler flag that makes each run faster, or a handover note saying “about 13 minutes,” both leave the number of runs untouched, and the number of runs is what needs cutting.
How a reviewer can catch this quickly
- In a design: any rule that says “runs the binary,” “over a fixture repository” or “end-to-end” next to “each” or “every.” Multiply it by how many things it covers and compare the result with the 1% target.
- In a brief: acceptance that says “tests pass” with no time attached, for work whose stated goal includes fast, isolated tests.
- In code: a helper that launches the program’s own binary, and then a count of how many tests call it.
- In any run: the summary line.
787s, 1118 teststells you enough without reading the diff. - In build config: an optimisation setting whose comment justifies it by what the tests do.
What I’m taking from this
This has happened to us before, more than once and in more than one language. Each time, the lesson went into our guidelines. This time the guidelines already described the problem almost word for word, and every session was pointed at them. They still failed, for four reasons:
- Pointing people at a rule isn’t the same as checking against it. I told sessions to “follow” guidelines, summarised away the part that mattered, and never turned it into a number anyone had to meet. Ten sessions followed the summary.
- The defect entered through the spec. Earlier cases grew one test at a time. This one was written down as a numbered rule on the same night as the rule that forbids it, and everyone after me built the newer rule without noticing the conflict. Reviewing tests has to start at the design page.
- A good review made it worse. The adversarial finding was correct, and its fix made each run bigger. A reviewer given a checklist didn’t check what wasn’t on it.
- Seeing a number isn’t the same as treating it as a finding. Four build stages saw it. One tuned the compiler, one wrote a note, two said nothing, and I reported the pass count as health.
The suite is being restructured now, with rule checks moving to unit tests and only a few end-to-end runs left. From here on, every brief I write carries a time limit, every report includes the suite’s measured time, and a design rule that conflicts with an approved one gets escalated, not built.