Journal13
Tests that hold on a busy machine

Weave: a striped cloth, every thread going over and under the threads across it, hung in folds. A cloth has thousands of crossings, and each keeps its place. It is 45 lines, and ships as 3,390 bytes.
Nilo’s tests failed now and then when the machine was busy, with several agents and builds running at once. Run again, they passed.
It is easy to call that bad luck and run them again. I made a rule instead. A test that fails and then passes on a second run has a fault in it, and the fault is found. It is never retried away.
The reason is simple. A test that sometimes fails for nothing teaches me to stop believing it. Then it is no use on the day it fails for something.
A model went looking for the causes, as it builds the rest. Most were tests that trusted the clock. The others thought they had the machine to themselves.
Trusting the clock
- One test held a build back and let it go after a tenth of a second, sure that the rest of the search would have finished by then. On a busy machine it might not have, and then the test complained that it had tested nothing.
- The check that drives the sketchbook in a browser pressed a key, waited 150 milliseconds, and looked. Once an edit reached the page, it gave the drawing 120. When an exported file appeared, it waited a fixed time and read it, whole or not.
- A test of how the tools give up on a reader that has stopped reading wanted that moment to land within 0.4 seconds of where it should.
- A test started twelve builds that never end, all at once, and expected the first of them to be the one stopped. Which one goes first is up to the machine.
The worst was quiet. Some tests need to see a program waiting to write, and a probe first asks whether the machine can show that. It gave the machine a fixed time. If the machine had not shown it by then, the tests were skipped, and a skipped test counts as passed. So on a busy machine, they passed without running.
Now they wait for the thing itself: the build to begin, the page to show the new build, the file to be whole, the search to be seen waiting for its workers. The test of giving up runs on a clock of its own, which it moves by hand. The test of twelve builds runs them one at a time to check the name, and side by side asks only that the message names one of them.
A wait still has a limit, a long one, so that something that never happens is said plainly instead of waited for forever. The probe’s limit is two minutes, and running out of it is a failure, never a skip.
Sharing the machine
- The scripts that start a sketch server asked for the same fixed ports on every run, so two runs at once would want the same port. Now the system hands each one a port that is free.
- The tool that installs new test answers takes a lock, so that two cannot install at once. One test held that lock itself, through a file it had open, then let go and expected the next run to get it straight away. But a program that another test starts in that moment carries a copy of every open file until it is under way, and until then it holds the lock too. The moment is short, but the test could land in it. Now the lock is held by a separate program, which the test kills.
Found on the way
Two faults turned up in the sketchbook page itself, not in the tests.
- Two requests for the newest build can come back in either order. If the older answer came last, it stayed on the page for good, since nothing asks again. Now the page takes only the answer to the request it made last.
- Moved to a screen of another sharpness, or after a change to the display settings, the page went on drawing for the old one, because no resize comes with that. Now it checks every frame and draws again.
The tools, in Go
The tools that run all of this were written in JavaScript, out of habit. They are Go now, like the compiler since
entry 9. nilotool check runs every check. nilotool bytes builds each piece twelve ways and compares the sizes with
the kept list. nilotool record shows, installs and puts back the saved test answers. Three of the four checks are
still scripts in JavaScript, because they have to run the JavaScript the compiler writes.
The move mended three things.
- Nothing is left running. Killed outright, the old check could leave a sketch server or a headless browser behind. One trial of the browser check alone, killed that way, left 12 programs running. Now each program the tool starts runs in a group of its own, and the group is stopped when the tool dies, however it dies. Killed outright in testing, it left nothing running.
- Nothing is lost. The old tool for the saved answers ended without waiting for its output to be read. When the reader was slow or busy, the rest was dropped: in one trial, 65,536 of 120,146 bytes arrived. The Go tools finish writing before they end. In a test, 819,986 bytes reached a reader that waited 15 seconds before it started, every one of them.
- Entry 10’s last item. It said that
accept, cut off at the wrong moment, could leave new answers in place that were never fully tested. Nowacceptwrites down what it is about to do before it replaces the first answer. If it is killed, the next run notices and stops, andrecord restoreputs the old answers back. That was tested by killing a real one outright, just after it had installed.
It got quicker too. Running its builds on every core took the size check from about 19 seconds to about 10, and the search running side by side, from entry 12, took it to about 3.
What is not right yet
- One failure still has no cause. Once in about 130 full runs of the Go tests, a test crashed inside Go itself, in the part that clears away memory no longer in use. It did not come back in 60 more runs of that test. It is not retried away: it is written down with what was seen, and if it comes back, the first thing to try is a newer Go, before looking in the compiler.
- A power cut in the middle of
acceptcan still leave a saved answer as it was before. The record it writes first then shows which one. - Faults in the checks themselves have been reported and are not fixed yet. The two scripts that start a sketch server can report success when the server did not stop. And the browser check does not watch for an error in the page that nothing catches, so a page that throws can pass.
- The way the tools handle the programs they start is written for Linux. Elsewhere they build, and say so when run.
The rule does not prove that the tests can no longer fail on a busy machine. It decides what a failure means.
Next
- Work through the list of known faults.
- Then the editor support.
The piece at the top
The image at the top comes from this token, built for the svg target:
0x90161818dcae5ea4699f157afc8806b5702710a6bd4518bcbb7823e4af5206d1
// weave: a striped cloth, every thread going over and under the threads across it, hung in folds
plate(1920, 2400)
use noise v2, colour v2
random layout, dye, yarn
let field = noise.table(layout)
let warps = layout.int(40 ..< 72), cell = layout.float(1150 ..< 1450) / warps, wefts = floor(1640 / cell)
// a warp thread (down) lies over a weft (across) where (i + j * step) % period < over: plain, or a twill
let period = layout.int(2 ..< 5), over = layout.int(1 ..< period), step = layout.chance(0.5) ? 1 : period - 1
// the stripes: each thread keeps the colour of the one before, until it changes; warp and weft alike
let inks = [#1d2b3a, #8c3b24, #d9a441, #ece6d8, #22362b, #b0302a, #1b1e2b, #e8d9a8, #3a2a4d, #b5482f, #e2cf9a,
#f3ede2, #24382e, #6b3f6e, #c98fae, #f0e8dc, #2a2a2a, #8a8f96, #c8c3b8, #f2efe8, #12304d, #2c6f8f, #e3b23c, #f1ece0]
let pick = dye.int(0 ..< 6) * 4
let stripe = color[]
var held = dye.int(0 ..< 4)
for i in 0 ..< max(warps, wefts) {
if dye.chance(0.12) { held = dye.int(0 ..< 4) }
stripe.add(inks[pick + held])
}
// folds that run down the cloth: a point is pushed sideways by the fold, and lit by its slope
fn fold(p: vec) = noise.octaves(field, point: vec(p.x * 0.002, p.y * 0.0005), layers: 2)
fn at(p: vec) = vec(p.x + 50 * fold(p), p.y)
fn row(j: int): vec[] = [at(vec(0, (j + 0.5) * cell)), at(vec(warps * cell, (j + 0.5) * cell))]
background(#e9e4da)
place(vec(960 - warps * cell / 2, 1100 - wefts * cell / 2), turn: layout.float(-0.006 ..< 0.006)) {
// a shadow on the paper; then row by row, the dark between the threads, and the thread on top at each crossing
place(vec(18, 26), opacity: 0.2) { for j in 0 ..< wefts { polyline(row(j), stroke: #2b2420, width: cell) } }
for j in 0 ..< wefts {
polyline(row(j), stroke: colour.darken(stripe[j], amount: 0.75), width: cell)
for i in 0 ..< warps {
let mid = vec(i + 0.5, j + 0.5) * cell, up = (i + j * step) % period < over
let lit = 8 * (fold(mid - vec(6, 0)) - fold(mid + vec(6, 0))) + yarn.float(-0.06 ..< 0.06) - (up ? 0 : 0.1)
let ink = colour.mix(up ? stripe[i] : stripe[j], toward: lit > 0 ? #fff6e8 : #000000, amount: abs(lit) * 0.6)
// a little longer than its square, so a float over several squares shows no seam; a sheen along it
let along = (up ? vec(0, 0.53) : vec(0.53, 0)) * cell
let a = at(mid - along), b = at(mid + along)
polyline([a, b], stroke: ink, width: cell * 0.88)
polyline([lerp(a, b, 0.2), lerp(a, b, 0.8)], stroke: colour.lighten(ink, amount: 0.12), width: cell * 0.3)
}
}
// the warp left loose at the foot, each end hanging in a curve of its own
for i in 0 ..< warps {
let p = at(vec(i + 0.5, wefts) * cell), sway = yarn.float(-14 ..< 14), fall = yarn.float(120 ..< 220)
curve([p, p + vec(sway, fall / 2), p + vec(sway * 2.5, fall)], stroke: stripe[i], width: cell * 0.45)
}
}