Skip to content

package main uses mutable globals as test seams, blocking t.Parallel #266

Closed

Description

@TMHSDigital

Summary

package main uses mutable package variables as test seams. Because tests overwrite them, none of the 16 root test files can use t.Parallel().

Where

  • main.go:75, main.go:79 (signalReady, testSignals)
  • main_ct.go:13 (ctBaseURL, waybackBaseURL)
  • main_axfr.go:17 (axfrPort)
  • main.go:599-610: a runArgs struct already injects the process environment

Why it hurts now

The e2e and lab tests in package main run serially, which makes them the slowest part of go test ./.... Each new seam adds more hidden global state.

Plan

  1. Add the five seams as fields on runArgs (signals channel, ready channel, source base URLs, AXFR port), defaulting to the production values.
  2. Migrate tests one seam at a time.
  3. Delete the globals.
  4. Add t.Parallel() to the hermetic tests.

Getting started

  • Relevant files: main.go, main_ct.go, main_axfr.go, root *_test.go
  • How to run tests: go test .
  • Related docs: docs/DEVELOPER_GUIDE.md

Filed by repo-audit/full-audit at 3f671b2. Severity: low. Effort: S. audit-key: tech-debt|main.go|test-globals

Activity

  1. added
    good first issue
    tech-debt
    severity: low
    on Nov 14, 2026
  2. TMHSDigital commented on Nov 14, 2026

    @TMHSDigital
    OwnerAuthor

    Partly done in 496df99 (plan steps 1-3): the five seams are now per-run fields on runArgs (signals, signalReady, sourceURLs, axfrPort), the tests pass them via runCLIWith/runCLIMergedWith, and the package variables are gone. Verified with the root package tests (x8 on Windows), golangci-lint v2.15.0 (windows and linux).

    Still open (step 4): adding t.Parallel() to the root tests. Each run calls signal.Notify and TestE2ESIGTERMExits143 sends SIGTERM to the whole process, so parallel runs would interrupt each other; that test (or signal handling) needs isolating first, and other package-level state should be audited before turning parallelism on.

  3. TMHSDigital commented on Nov 14, 2026

    @TMHSDigital
    OwnerAuthor

    Step 4 is done in d0c56f0: 58 TestE2E* tests in the root package now call t.Parallel(), which cuts go test . from about 10.5 s to 3.6 s on Windows.

    Seven stay serial on purpose: the ones that call t.Setenv or os.Chdir (they panic or race under t.Parallel), and TestE2ESIGTERMExits143. Go runs every serial top-level test before it resumes any parallel one, so that test's process-wide SIGTERM can't reach a parallel run. The other shared state I found is safe: the default SUBENUM_STATE file is only written after a signal, and TestE2EResume passes its own -state.

    Verified with go test -race -shuffle=on -count=4 . on Windows and three shuffled runs of a Linux test binary under WSL, including the SIGTERM test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueseverity: lowtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions