weekly log · issue 12 · cleaning up the tests
From 838 to 265 seconds: we cut half our tests and brought back the ones that guarded something
The training module ran 860 tests in 838 seconds. We measured, cut half, and another agent reviewed what was deleted: 10 groups of rules came back. We ended with 458 tests, 265 seconds and everything green.
- The training module's 860 tests took 838 seconds; 579 of them were setup. We fixed the setup and judged each test: what rule does it guard, and does anyone else guard it?
- We ended with 458 tests in 265 seconds, all green. Another agent reviewed what was deleted, and 10 groups of security, permission and quality rules came back.
- In Sales we broke 25 rules on purpose and all 25 were caught. The one-minute goal is still in the red: in parallel we're at 105 seconds.
Every time we changed something in the staff training module, the computer ran 860 tests before letting us move on. It took 838 seconds: almost 14 minutes.
Fourteen minutes sounds like little. But you pay it every time someone fixes a label, a permission or a screen. And when something takes that long, it suffers the worst thing that can happen to an alarm: people run it less, or stop looking at it. Of those 860, 7 were still red and one threw an error.
On November 29 we cleaned house. The result: 458 tests that take 265 seconds, all green. But what I want to tell you about isn't the number. It's how we decided what to remove without going blind.
What a test is, without jargon
A test is a tiny program that watches over one rule. "An exam with an invalid answer doesn't get published." "No one sees the data of a person from another company." "A certificate that's already sealed doesn't change." If someone breaks the rule by accident, the test turns red before the change reaches the operation.
Over the months they pile up. Some watch the same thing as others. Others watch things that no longer exist. And some fail for reasons that have nothing to do with their rule: in the ones we checked, the test expected a fixed number of courses and the catalog had already grown. The rule was fine; the test was old.
Where the 14 minutes went
Before removing anything, we measured. Of the 838 seconds, 579 were setup and 253 were the tests themselves. Almost all the time went into setting the table, not eating.
We found two culprits, with a stopwatch:
- Before each test, all 132 tables of the test database were emptied, even if the test used only a few. That cost 0.43 seconds per test.
- During setup, the whole course catalog was validated again: 1.4 seconds each time.
The fix was simple: empty only the tables that were used, and don't validate the courses again for every test. No rule changed because of it.
Judging each test
Then we went through the 154 test files one by one. Each got a verdict: stays, gets shorter, merges with another, or goes. The question was always the same: what rule does it guard, and does anyone else guard it?
And there was one condition for whoever cuts: if a test guards security, permissions or quality and nothing else guards that rule, before removing it you write down what protection is lost. The report has that list, item by item. What's lost stays in plain sight, not hidden behind a nicer number.
Before and after
- Tests: from 860 to 458.
- Cases that run: from 1,010 (7 red and 1 error) to 564, all green.
- Lines of test code: from 14,618 to 9,240.
- Seconds, one after another: from 838 to 265.
- Seconds, in parallel: 105 (never measured before).
Code nobody used anymore went out too: four tools written to run a single time, and two unused functions.
The second opinion
Whoever cuts shouldn't be the one who signs off that it went well. So another agent, one that didn't make the change, reviewed everything that was deleted.
It found two things. The good one: nothing that was removed was in use, and the new setup showed no visible failures. The important one: 10 groups of security, permission and quality rules had been left without a test. Those tests came back before the change was merged.
That's why the title says "brought back the ones that guarded something." Without that second look, the number would have come out nicer and the system blinder.
Breaking things on purpose
Two days earlier we did the same in the Sales module, and there we went one step further. It went from 544 tests to 224, and from 22.0 to 13.3 seconds.
Then we broke 25 rules on purpose, one at a time: rules about money, permissions, Quality's signature and the evidence for what gets discarded. If the cleanup had left a gap, the broken rule would have slipped through without anyone noticing. In all 25, some test turned red.
And something turned up that we weren't looking for: the rule "a sale isn't closed without a valid Quality signature" had no test, neither before nor after. We wrote one. Sometimes cleaning up is the only way to see what was missing.
A slow test doesn't protect less because it's slow. It protects less because it stops being run.
What we don't know
- Whether everything in training is still guarded. There we haven't broken rules on purpose yet, as we did in Sales; the review was done by reading. That's the first thing still missing.
- What some old tests were watching. According to the reviewer, four parts of the code stopped being exercised by the tests, among them a per-site permission and access to the course videos. We haven't checked what they were watching.
- How much of the code they cover. We didn't measure which part of the program each test touches; the tool to measure it isn't even installed.
- Whether we'll get to one minute. The goal was under 60 seconds. In parallel we're at 105: still in the red against that goal.
What comes next
Break the training rules on purpose, as we did in Sales, before calling the cleanup good. Finish merging the files that were only half merged and trim repeated cases, to get closer to one minute. And measure coverage, so the next discussion is about numbers and not hunches.
Meanwhile we adopted a working rule: on a small change, only the tests for what was touched run, and the full suite runs when I ask for it. That rule is only safe if the full suite is fast and reliable on the day it does run. That's what this cleanup was for.
AI recommends; people decide. And alarms need looking after too: BIEN y a Tiempo (done right and on time) means they go off when they should, and someone turns to look.
How many of the alarms in your operation keep ringing without anyone turning to look? Write to me.
Miguel Marengo Canales · Silodisa
Comments
comments · I answer every one. If you disagree, even better: say it with numbers.