I made our CI 45 minutes slower and then raised the timeout so nobody would notice
This is a post-mortem on a mistake I made recently. The CI job for one of our apps had slowed to a crawl. When I looked into it, I found the cause in code and config I had written myself. Here’s what I did, why it was wrong, and what I’m changing.
The symptom
The last stretch of the test run was one serial group of integration tests. The final 19 tests took about 24 minutes together, an average of more than a minute each. The fastest of them still took about 45 seconds, so that was the minimum cost of a test even when the thing it tested was fast. The whole group has a few dozen tests and runs one at a time, so the times add up: roughly 45 to 50 minutes of every CI job, plus the cost of building the toolchain on a cold machine.
Nothing in that group was slow because of what it was testing. It was slow because of how I built it.
What I did wrong
1. I hard-wired the real compiler into the engine
Our app runs an engine that compiles user-written packages with an external language toolchain: a compiler, a package manager, and a WebAssembly build step. The library we use for this was designed with a seam for tests. You pass in a “tool runner”, and in tests that runner can replay recorded toolchain output instead of running the real tools.
I closed that seam. The engine’s constructor and the package compiler both built the language module with its default live toolchain. Neither one let a caller pass in a different runner. The library had a clean way to swap in a replay implementation, and my layer took that choice away from everything above it.
2. I stubbed the cheap part and left the expensive part live
Every integration test opened a real engine, compiled a real package with the real compiler, and prepared every program it ran with the real package manager. I did stub the user-facing commands that the pipelines call, and I was pleased with myself for keeping the tests controlled. But those commands were never the slow part. The compiler was, and I left it running for real.
3. I made the CLI tests spawn the full binary every time
The command-line tests started the built binary as a fresh subprocess, in a fresh git checkout of a fixture repository. Each process opened the engine from scratch and went through the whole compile path. Some tests edit the package on purpose, so they skip the build cache and pay for a full build. One test also drives an interactive terminal prompt through a pipe, which made it the slowest of all.
Most of these tests check which pipeline was selected, which files were written, exit codes, and printed output. None of that needs a compiler.
4. I raised the timeout instead of fixing the tests
This is the part I’m least proud of. Our test runner had a per-test time limit of 2 minutes. My tests went over it, so I moved them into their own group: run alone, no retries, and a limit of 45 minutes per test. I even left a comment saying these tests “may run for many minutes on a cold machine.”
So I knew. I saw the cost, wrote it down, and accepted it.
The time limit exists to reject implementations that take that long. Raising it to get the suite passing doesn’t fix anything. It just lets a badly written implementation through. When a test needs the limit raised, that test is the problem, and the fix belongs in the test. The limit should not move.
5. I misread “real engine” as “real everything”
Our design docs say the engine’s host operations and permission checks must be tested “through a package run in a real engine.” I took “real engine” to include a real compiler. What it actually means is the runtime, the host functions, and the sandbox: the parts we wrote and need to check. The compiler is a dependency behind a boundary, and the library we depend on already had a rule for that boundary: one live test suite per repository, and every other test replays recorded output.
I never read that rule because it lives in the dependency’s docs, not ours. Then every suite I wrote later copied the first one’s shape, and the mistake grew.
What I should have done
The tools to do this right were already there:
- Keep the seam open. The engine and compiler constructors should accept a toolchain or tool runner. The current constructors can stay as the convenient live default.
- Have exactly one live suite. Keep a small set of tests that prove the real toolchain works: the tree compiles, the guest builds, one package compiles and is served from the cache, and a missing tool produces a clear error. Label it as the repository’s single live suite.
- Replay everywhere else. The engine tests can still use a real engine, real sandbox, real host functions, and real permission checks. Only the compiler subprocesses get replayed from committed recordings. The replay matches on the tool, its arguments, and hashes of the files it reads. When the SDK or a fixture changes, the recording fails loudly instead of quietly drifting.
- Test the CLI in-process. Put the engine behind the interface the commands already use, and test the commands against a replaying engine or a fake loaded with a pre-built library. Keep at most one end-to-end test that spawns the binary as a smoke check, and leave the rest of the binary-level coverage to the end-to-end suite.
- Put the timeout back to 2 minutes. It should be a real limit again.
What I’m changing going forward
- When I depend on a library with a test seam, I’ll read its testing docs before writing tests against it. The rule I broke was written down. I just never opened the page.
- When a test is slow, I’ll find out what is slow before deciding it’s fine. I stubbed something because it was easy to stub. The slow part was what I needed to stub.
- I won’t raise a timeout to get a test passing. If a test needs more time, that’s the bug report.
- I’ll write the rule down where the next person will see it. We’re adding the boundary rule to our own testing docs and contributor guide, so nobody has to find it in a dependency’s source comments. In short: the toolchain is only reached through the tool runner, one suite runs it live, everything else replays a committed recording, and “real engine” means our runtime, not the compiler behind it.
- I’ll be careful about copying the shape of earlier tests. Every later suite copied the first one, and so did its cost. A pattern people copy needs a closer review the first time it’s written.
None of this was hard to get right. The design already pointed the right way, and I worked around it, then changed the config so the cost wouldn’t show. I’m sorry for the CI minutes this burned. The fix is in progress.