Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Run the integration tests in parallel: 168s of tests becomes 16s

44530e746def72216bf02e88716f121936576ab7 · Keenan Nemetz · 17d ago · parent 6c03e461

Run the integration tests in parallel: 168s of tests becomes 16s

The suite was serial, and it is the wrong shape to be serial. 95 tests in
internal/server each start a server, push over SSH and shell out to git, so
they spend nearly all their time waiting on child processes and almost none
on CPU: the package took 148s wall for 23s of user time. Sixteen cores were
sitting idle while tests waited for git.

Every test now calls t.Parallel(). Nothing else about the fixtures had to
change, because they were already isolated the way parallelism needs: each
gets t.TempDir(), binds 127.0.0.1:0, and passes its environment through
cmd.Env rather than the process's. binPath is built once by TestMain and is
read-only.

Measured on 16 cores: internal/server 148.4s -> 12.8s, the whole suite
168s -> 16s, and `scripts/ci.sh` (gofmt, vet, build, link check, then the
whole suite under -race) 19.5s end to end. Verified stable across six
repeated runs, two `-shuffle=on` runs and two `-race` runs, with no data
races reported, so the parallelism is exposing isolation the fixtures
already had rather than luck.

The critical path is now one test, TestKilledRunnerIsRequeued, because it is
genuinely a timing test: it waits for a lease to expire and for the requeue
sweep. Its fixture workflow held the step for `sleep 8`, which also runs on
the retry, so eight of its fourteen seconds were the fixture waiting for
itself. Three seconds keeps the property it is testing — the runner must
still be working when it is killed, and the kill happens as soon as the lease
is visible — and takes the test to 9.7s.

What is left is fixture setup, and most of it is SQLite schema creation:
runs.Open is ~89ms and index.Open ~58ms on a *fresh* file. Measured, that is
not the eleven ALTER TABLE statements that are expected to fail on "duplicate
column" — on a warm connection those cost 2us for all eleven. It is the
CREATE TABLE / CREATE INDEX work itself, and modernc's pure-Go engine is much
slower at DDL than C SQLite. Reopening an already-created database is 408us,
so this is a cost paid once per database file, not once per open: in
production it is `vole init` and nowhere else. Tests pay it 95 times because
every fixture starts from an empty data directory.

Left alone deliberately, for two reasons. It is ~1s of wall time across the
suite, and the only fixes available are test-side (build the empty databases
once in TestMain and copy the files per fixture) or would mean changing
storage engines — which is the wrong conclusion from 150ms, and is not what
those 89ms are about.

The invariant is written down at the top of internal/server's test file, with
the rules a new test has to keep: no t.Setenv, no fixed paths, no shared
state beyond binPath, no ordering assumptions, and the shortest sleep a
fixture can get away with — because a test's own wait sets the floor for the
whole package and parallelism cannot hide it.

internal/gitx and cmd/vole keep `t.Setenv` tests, which cannot be parallel,
so those packages are unchanged. They take 0.2s and 0.5s.

internal/server/reconcile_test.go +6

@@ -120,6 +120,7 @@ jobs:
120 120 // A ref tip no cursor has recorded is work owed — that is the whole reason the queue
121 121 // is reconciled from git rather than from the spool file a crash may have eaten.
122 122 func TestReconcileQueuesATipTheQueueHasNeverSeen(t *testing.T) {
123 t.Parallel()
123 124 h := newReconcileHarness(t)
124 125 h.commit(t, "refs/heads/main", testWorkflow)
125 126
@@ -139,6 +140,7 @@ func TestReconcileQueuesATipTheQueueHasNeverSeen(t *testing.T) {
139 140 // The promise this buys: deleting the queue loses at most the job that was running.
140 141 // The refs still say what is live, so the work comes back.
141 142 func TestReconcileRebuildsAQueueThatWasDeleted(t *testing.T) {
143 t.Parallel()
142 144 h := newReconcileHarness(t)
143 145 h.commit(t, "refs/heads/main", testWorkflow)
144 146 h.s.reconcileRefs()
@@ -171,6 +173,7 @@ func TestReconcileRebuildsAQueueThatWasDeleted(t *testing.T) {
171 173 // The metadata branch is full of entities and run records; a build must never be
172 174 // queued for it, however its tip moves.
173 175 func TestReconcileIgnoresTheMetadataBranch(t *testing.T) {
176 t.Parallel()
174 177 h := newReconcileHarness(t)
175 178 commit := h.commit(t, "refs/heads/main", testWorkflow)
176 179 if err := h.repo.Git().UpdateRef("refs/heads/vole", commit); err != nil {
@@ -186,6 +189,7 @@ func TestReconcileIgnoresTheMetadataBranch(t *testing.T) {
186 189 // Pushing twice must not leave the first commit's build queued behind the second's:
187 190 // a new tip cancels what was waiting for the old one.
188 191 func TestANewerTipCancelsTheQueuedBuildOfTheOlderOne(t *testing.T) {
192 t.Parallel()
189 193 h := newReconcileHarness(t)
190 194 first := h.commit(t, "refs/heads/main", testWorkflow)
191 195 h.s.reconcileRefs()
@@ -214,6 +218,7 @@ func TestANewerTipCancelsTheQueuedBuildOfTheOlderOne(t *testing.T) {
214 218 // account may run, and the old name no longer exists — and a stranded cursor makes the
215 219 // next reconciliation build the current tip a second time.
216 220 func TestRenamingARepositoryCarriesItsQueue(t *testing.T) {
221 t.Parallel()
217 222 h := newReconcileHarness(t)
218 223 h.commit(t, "refs/heads/main", testWorkflow)
219 224 h.s.reconcileRefs()
@@ -252,6 +257,7 @@ func TestRenamingARepositoryCarriesItsQueue(t *testing.T) {
252 257 // A deleted branch drops its cursor, so the branch coming back at a new tip is work
253 258 // owed rather than work suppressed by a note about a branch that no longer exists.
254 259 func TestReconcileDropsTheCursorOfADeletedBranch(t *testing.T) {
260 t.Parallel()
255 261 h := newReconcileHarness(t)
256 262 h.commit(t, "refs/heads/main", testWorkflow)
257 263 h.s.reconcileRefs()