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/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0: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 · 16d 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/sshserver/sshserver_test.go +8

@@ -237,6 +237,7 @@ func (h *harness) serverRef() string {
237 237 }
238 238
239 239 func TestPushAndCloneOverSSH(t *testing.T) {
240 t.Parallel()
240 241 h := newHarness(t)
241 242 work := workRepo(t)
242 243
@@ -263,6 +264,7 @@ func TestPushAndCloneOverSSH(t *testing.T) {
263 264 // TestReadOnlyUserCannotPush proves the hook sees the SSH identity: the
264 265 // rejection has to name the user, not just fail.
265 266 func TestReadOnlyUserCannotPush(t *testing.T) {
267 t.Parallel()
266 268 h := newHarness(t)
267 269 work := workRepo(t)
268 270 if _, errs, err := h.git(work, h.keyPath, "push", h.url(), "main:refs/heads/main"); err != nil {
@@ -295,6 +297,7 @@ func TestReadOnlyUserCannotPush(t *testing.T) {
295 297 // TestExecWhitelistRefusesShell is the security test for this transport. A
296 298 // session that can exec arbitrary commands is a remote shell.
297 299 func TestExecWhitelistRefusesShell(t *testing.T) {
300 t.Parallel()
298 301 h := newHarness(t)
299 302 client := h.dial(t, h.keyPath)
300 303
@@ -322,6 +325,7 @@ func TestExecWhitelistRefusesShell(t *testing.T) {
322 325 }
323 326
324 327 func TestShellRequestRefused(t *testing.T) {
328 t.Parallel()
325 329 h := newHarness(t)
326 330 client := h.dial(t, h.keyPath)
327 331 sess, err := client.NewSession()
@@ -335,6 +339,7 @@ func TestShellRequestRefused(t *testing.T) {
335 339 }
336 340
337 341 func TestUnknownKeyRejected(t *testing.T) {
342 t.Parallel()
338 343 h := newHarness(t)
339 344 stranger, _ := keypair(t, filepath.Join(h.dir, "stranger"))
340 345 if _, err := ssh.Dial("tcp", h.addr, &ssh.ClientConfig{
@@ -348,6 +353,7 @@ func TestUnknownKeyRejected(t *testing.T) {
348 353 }
349 354
350 355 func TestRepoOutsideTheStoreIsRefused(t *testing.T) {
356 t.Parallel()
351 357 h := newHarness(t)
352 358 client := h.dial(t, h.keyPath)
353 359 for _, arg := range []string{
@@ -404,6 +410,7 @@ func publicKey(t *testing.T, path string) ssh.AuthMethod {
404 410 }
405 411
406 412 func TestSplitCommand(t *testing.T) {
413 t.Parallel()
407 414 for _, c := range []struct {
408 415 in string
409 416 want []string
@@ -434,6 +441,7 @@ func TestSplitCommand(t *testing.T) {
434 441 }
435 442
436 443 func TestRepoNameValidation(t *testing.T) {
444 t.Parallel()
437 445 for _, c := range []struct {
438 446 in, want string
439 447 ok bool