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/hook/hook_test.go +6

@@ -108,6 +108,7 @@ func (f *fixture) setACL(mut func(*acl.ACL)) {
108 108 }
109 109
110 110 func TestOwnerCanPush(t *testing.T) {
111 t.Parallel()
111 112 f := newFixture(t, "hello\n")
112 113 if code, out := f.run("owner", "refs/heads/main", 0); code != 0 {
113 114 t.Fatalf("owner push rejected: %s", out)
@@ -118,6 +119,7 @@ func TestOwnerCanPush(t *testing.T) {
118 119 }
119 120
120 121 func TestReadOnlyCannotPush(t *testing.T) {
122 t.Parallel()
121 123 f := newFixture(t, "hello\n")
122 124 code, out := f.run("reader", "refs/heads/main", 0)
123 125 if code == 0 {
@@ -132,6 +134,7 @@ func TestReadOnlyCannotPush(t *testing.T) {
132 134 }
133 135
134 136 func TestAnonymousCannotPush(t *testing.T) {
137 t.Parallel()
135 138 f := newFixture(t, "hello\n")
136 139 code, out := f.run("", "refs/heads/main", 0)
137 140 if code == 0 {
@@ -143,6 +146,7 @@ func TestAnonymousCannotPush(t *testing.T) {
143 146 }
144 147
145 148 func TestProtectedBranch(t *testing.T) {
149 t.Parallel()
146 150 f := newFixture(t, "hello\n")
147 151 f.setACL(func(a *acl.ACL) { a.Protected = []string{"refs/heads/main"} })
148 152
@@ -160,6 +164,7 @@ func TestProtectedBranch(t *testing.T) {
160 164 }
161 165
162 166 func TestOversizedBlobRejected(t *testing.T) {
167 t.Parallel()
163 168 f := newFixture(t, strings.Repeat("x", 4096))
164 169 code, out := f.run("owner", "refs/heads/main", 1024)
165 170 if code == 0 {
@@ -174,6 +179,7 @@ func TestOversizedBlobRejected(t *testing.T) {
174 179 }
175 180
176 181 func TestArbitraryRefsRejected(t *testing.T) {
182 t.Parallel()
177 183 f := newFixture(t, "hello\n")
178 184 // refs/vole is no longer server state (access rules moved into the database), but it
179 185 // is still not a branch or a tag, so it is refused by the same rule as any other