Our Functional test suite had been red for months, and nobody saw it, because CI never ran it.

That sounds like a small omission. It was 137 files and about 850 tests that would have cost 11 seconds on top of the Unit suite’s 26. But a suite that’s already red can’t tell you anything new. A real regression looks exactly like the failures that were there yesterday, which is how an earlier attempt at this same work reached master and got reverted half an hour later.

So the job was to make it pass, and then to make CI run it. Some of the failures were stale assertions. The rest were more interesting.

The test that had been wrong since May

The clearest example of what a red suite costs was a search test. In May I removed a rule that dropped short search terms, and wrote about why. That change updated four Unit test files and missed one Functional test, which went on asserting the old behavior.

The code was right. The test was demanding the exact false positive the search work had set out to remove. It stayed red for three and a half months, in the same suite as everything else, and looked like nothing in particular.

A rollback that didn’t roll back

Each Functional test runs inside a transaction that gets rolled back afterwards. Three tests needed a table that wasn’t in the template, so they created it themselves, from what their comments called a “side connection”.

There was no side connection. Our wrapper reuses the global connection, so the CREATE TABLE ran on the same session that held the test’s transaction. In MySQL, that’s an implicit commit. I confirmed it on a throwaway MySQL 8.4 container:

START TRANSACTION;
INSERT INTO a VALUES (2);
CREATE TABLE b (id INT);
ROLLBACK;
-- the row is still there

So everything those tests had written became permanent and leaked into every test that followed. One of them had even noticed the fallout and worked around it with a manual DELETE.

Creating the table once in the bootstrap, outside any transaction, took the suite from 27 failures to 17 with nothing newly broken. The same commit showed how deep this went: one test file only passed because a stale cached config answered “installed” for a module it never installed.

The fix that fixed nothing

The plan said the contamination between tests came from per-tenant static caches. That was a reasonable theory, so I wrote the reset for all of them and ran the suite:

before: 849 tests, 1 error, 26 failures, 2714 assertions
after:  849 tests, 1 error, 26 failures, 2714 assertions

Byte-identical. The diagnosis was wrong, and that number disproved it. The commit message says so in capitals, because the temptation with a fix like that is to keep it and let everyone assume it worked. The real mechanism ran in both directions: one test failed alone and passed when almost any other file ran first.

I kept the reset anyway, because one entry was a verified leak rather than a guess.

What sorted file names were hiding

Once the suite was close, I ran it in random order, and a new failure appeared. A helper switched off mysqli’s error reporting to probe for an optional database, and never put it back:

mysqli_report(MYSQLI_REPORT_OFF);

mysqli_report() is process-global. A quick test confirmed it: after calling it inside a closure, a failed connection anywhere else in the process stopped throwing and just set an error code. So every test that ran afterwards got a mysqli that doesn’t throw, and a test asserting that a bad select_db throws would fail.

It wasn’t a flake. That test passed alone and failed whenever the helper’s file ran first, and sequential runs hid this only because Infrastructure sorts before Modules. The fix was to catch the connection failure instead of changing global state. The suite now passes in random order, three times over.

The correct test I rewrote

This one was mine. A holiday test expected a range of 24 to 26 December, which failed. I looked in the seeded table, found Juleaften (Christmas Eve) in it, decided the test was stale, and moved the range to 23 to 25 December.

It was wrong. A sync job rebuilds that table in production from a whitelist of names, and Juleaften isn’t on it. 24 December is an ordinary working day here unless a customer opts in. The test had been right about production all along, and the fixture was the outlier. I reverted my own change the same day.

The lesson went into a guard test: compare the fixture against the sync script’s whitelist, so the two can’t quietly disagree. Then I noticed that it only proved the fixture was clean today, not that it would notice a dirty one. I’d checked that by hand, once, on one machine. So the comparison moved into a helper with tests that assert it rejects, including the case where the whitelist stops being parseable. That’s the failure that would have let the guard die quietly.

Green here, red in CI

That guard earned its keep about two weeks later. The suite passed on my machine and failed in CI, and the guard was what caught it.

MySQL’s Docker entrypoint pipes the seed files through the mysql client, and the client’s default character set in that image is latin1. Reading a UTF-8 file as latin1 and storing it as utf8mb4 double-encodes it. I reproduced it in a clean container: å should be C3A5, and it was stored as C383C2A5.

Nothing errors, and a reader that also speaks latin1 gets the right string back. Locally, PHP had that same latin1 handshake, so everything looked fine. In CI it didn’t, and Nytårsdag no longer matched the whitelist. This is the reason for having one database definition shared by CI and developers, and even then it took a guard test to see the gap.

What actually blocks a merge

CI now runs the suite on every pull request, and errors and failures block the merge. Warnings and deprecations don’t, even though the suite has plenty: 189 warnings and 194 deprecations when this merged. They’re shown to the reviewer instead, because they’re inherited debt, and blocking someone over debt they didn’t create teaches people to dismiss the bot. Once that’s a habit, the real signals go with it.

The takeaway

A test suite is only worth what its failures mean. The moment “red” stops being news, the suite has stopped working, however many tests it contains, and fixing it isn’t a chore you do for tidiness. It’s what lets the next failure be a signal.

The other lesson came from my own mistakes. Twice here the obvious explanation was wrong: the cache theory that changed nothing, and the stale test that wasn’t stale. Measure the run before and after, even when you’re sure. And when a test disagrees with your fixture, find out what regenerates the fixture before you decide which one is lying.