Skip to content

test: t.Parallel across seventeen files, and one test that passed by luck (#179) - #374

Merged
scttfrdmn merged 3 commits into
mainfrom
test/paralleltest-burndown-179
Aug 7, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
test/paralleltest-burndown-179

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Part of #179. Does not close it — the remaining 299 findings are other linters plus 141 paralleltest/tparallel in packages not touched here.

The number

before after
total 570 299
paralleltest 385 134
tparallel 27 7
everything else 158 158

t.Parallel() on every test and subtest in seventeen files across pkg/errors, pkg/status, pkg/health, pkg/recovery, pkg/retry, pkg/api, pkg/utils, pkg/types, internal/cache and internal/metrics. CLAUDE.md already requires this; the finding count was the gap between the requirement and the tree.

Every package was run under -race -count=2 after the change and its coverage checked against its floor. That matters more than it sounds: parallelizing a test that shares state is a way to make it pass less often, not a way to make it faster, so a green single run proves nothing.

Two packages resisted, and that is the point

pkg/health — a test that was passing on subtest ordering

TestTracker_CanRead wrote a component's State directly and asserted what CanRead/CanWrite answered. But State alone does not decide that. admissionState admits one probe against a refusing component once nextProbe has elapsed, and reports StateDegraded to get that probe past the gate:

state, due := health.State, health.nextProbe
t.mu.RUnlock()

if t.config.ProbeAfter <= 0 || state == StateHealthy || state == StateDegraded {
	return state
}
if time.Now().Before(due) {
	return state
}

return t.probe(component)   // returns StateDegraded

So State=StateUnavailable with a zero-value nextProbe — always in the past — reads as readable. That is not a combination the tracker ever produces: RecordError sets both fields, and the test set one.

One tracker shared across the table concealed it. The first subtest to reach a refusing state took the probe path, which pushed nextProbe ProbeAfter into the future, and every later subtest then read raw state and agreed with the table. The assertion held on the order its siblings happened to run in.

Giving each subtest its own tracker — the isolation t.Parallel() requires anyway — removed the accident, and the unavailable case failed immediately:

--- FAIL: TestTracker_CanRead/unavailable
    health_test.go:180: CanRead() = true, want false for state unavailable

Fixed by setting nextProbe alongside State, in the shape RecordError leaves it. Verified by deleting that line: the unavailable case fails. -race -count=5 green after.

No production defect — the tracker's own code path sets both fields together. What was broken is a test that could not have caught it if they came apart.

pkg/utils/debug_mode_test.go — 19 findings a t.Parallel() cannot fix

Filed as #373 and excluded in .golangci.yml with the reasoning recorded.

DebugManager is a sync.Once singleton with no exported constructor, so every test observes the same instance. That alone would be workable — each test already uses a distinct session ID. The blocker is DebugManager.RecordEvent, which fans every event out to all open sessions:

for _, session := range sessions {
	session.RecordEvent(component, operation, message, fields, goroutineID)
}

A session's event count is therefore a function of what every other concurrently-open session recorded. Adding t.Parallel() to all 19 and running -race -count=4:

TestRecordEvent            Expected 1 event, got 2
TestGetEventsByComponent   Expected 2 storage events, got 6
TestGetStats               Expected 3 events in stats, got 8
TestDebugTrace             Expected 1 event, got 17
TestDebugTrace_WithError   Expected 1 event, got 17

No data race — the locking is correct, and the broadcast is doing exactly what it is written to do. Suppressed rather than silenced with a false t.Parallel(), which would have left the tests sequential in effect and the lint green: the worst of both. #373 proposes an exported constructor so each test can own a manager, which is the fix that makes the exclusion removable.

A note on the transform

The mechanical pass had a bug worth mentioning because it produced a loud failure rather than a quiet one. Its first version inserted t.Parallel() without checking whether the closure already called it further down, which yields panic: testing: t.Parallel called multiple times in pkg/api. Fixed to scan the closure body up to its first nested t.Run, reverted and reapplied — 2 insertions rather than 4 in that file. All seventeen files were then scanned for doubled calls; none.

Verification

go build ./...                                    clean
go test -race -count=2 ./pkg/... ./internal/cache/... ./internal/metrics/...    all pass
golangci-lint run --enable-only=paralleltest,tparallel <touched packages>       0 issues

Coverage held at each package's floor: pkg/status 93.0%, pkg/health 93.5%, and the rest unchanged.

…luck (#179)

278 of the paralleltest/tparallel backlog cleared: 570 lint findings to 299.
t.Parallel() on every test and subtest in pkg/errors, pkg/status, pkg/health,
pkg/recovery, pkg/retry, pkg/api, pkg/utils, pkg/types, internal/cache and
internal/metrics. CLAUDE.md already required this; the finding count was the gap
between the requirement and the tree.

Each package ran under -race -count=2 after the change with its coverage checked
against its floor, because parallelizing a test that shares state is a way to make
it pass less often rather than a way to make it faster. Two packages resisted, and
both are why this was worth doing rather than suppressing.

pkg/health's TestTracker_CanRead had a real order dependency. It wrote a
component's State directly and asserted what CanRead answered, but State alone does
not decide that: admissionState admits one probe against a refusing component once
nextProbe has elapsed, and reports StateDegraded to get that probe past the gate.
So State=StateUnavailable with a zero-value nextProbe — always in the past — reads
as readable, a combination the tracker never produces, since RecordError sets both
fields and the test set one.

One tracker shared across the table concealed it. The first subtest to reach a
refusing state took the probe path, pushing nextProbe ProbeAfter into the future,
and every later subtest then read raw state and agreed with the table. Giving each
subtest its own tracker — the isolation t.Parallel requires — removed the accident
and the unavailable case failed with CanRead() = true, want false. Fixed by setting
nextProbe alongside State in the shape RecordError leaves it, and verified by
deleting that line and watching the case fail. No production defect: the tracker's
own path sets both fields together. What was broken is a test that could not have
caught it if they came apart.

pkg/utils/debug_mode_test.go's 19 findings cannot be fixed by a t.Parallel at all.
DebugManager is a sync.Once singleton with no exported constructor, and RecordEvent
fans every event out to all open sessions, so a session's event count depends on
what every concurrently-open session recorded. Measured: "Expected 1 event, got
17", and five other counts inflated by siblings' traffic, with no data race — the
locking is correct and the broadcast does what it is written to do. Excluded in
.golangci.yml with that reasoning and filed as #373, rather than silenced with a
t.Parallel that would leave the tests sequential in effect and the lint green.
Runs 31126521849 (CI) and 31126521846 (Security) were created at 18:57Z during
the incident and never materialized as jobs: both report status=queued with
zero jobs and run_attempt=1, despite a `gh run rerun --failed` being accepted
at 20:25Z. Their three cancelled checks — Security Scan, docs-site, and
fuzz-smoke (./internal/storage/s3, FuzzRoundTrip) — each recorded steps=0 after
sitting queued 77-87 minutes, which is the queue timeout GitHub's incident
warned about rather than any finding. The other 27 checks on this PR passed.

Nothing about the tree changed. The incident was mitigated at 00:06Z and the
same approach on #379 dispatched immediately, so this is a clean re-dispatch
rather than a fix.
@scttfrdmn
scttfrdmn merged commit 4414596 into main Aug 7, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the test/paralleltest-burndown-179 branch August 7, 2026 00:50
scttfrdmn added a commit that referenced this pull request Aug 7, 2026
Four conflicts, all in tests both sides had independently improved, and
three of the four would not compile if resolved to main's side:

- internal/cache/persistent_test.go — main added an outer tmpDir that the
  body never uses (each subtest makes its own), so it would be an unused
  variable. Kept this branch's plain t.Parallel().
- pkg/api/server_test.go (x2) — kept NewRequestWithContext(t.Context(), …)
  over plain NewRequest, so the request dies with the test.
- pkg/health/health_test.go — both sides fix the same bug. Kept the side
  that drives the component through transitionState, which already arms
  nextProbe (health.go:469-474); main's side hand-assigns State and
  nextProbe and can therefore drift from production.
- pkg/recovery/recovery_test.go — main's DegradedState literal leaves
  `config` undefined and mismatches every assertion below it
  ("test-component", "read-object: boom", AttemptCount, RecoveryBackoff).
  Kept markDegraded through the production path.

Also deletes .golangci.yml's paralleltest exclusion for
pkg/utils/debug_mode_test.go, which arrived from main via #374. Its
rationale said "#373 tracks giving the manager a constructor … which is
the fix that makes the exclusion removable" — this branch is that fix:
NewDebugManager exists (debug_mode.go:60) and the file now has 19
t.Parallel() calls. Leaving the exclusion would suppress a linter that
has nothing left to report.
scttfrdmn added a commit that referenced this pull request Aug 7, 2026
Second sync: #374 and #375 both landed after this branch's last merge.

- go.mod / go.sum — kept substrate v0.93.0 over main's v0.92.0. Same bump,
  this branch is one release ahead; `go mod tidy` is clean at v0.93.0.
- CHANGELOG.md, three regions — two were both-sides additions to the same
  section, kept in full. The third is the substrate entry both sides wrote:
  kept the v0.93.0 text, which also carries the v0.93.0-only finding that
  If-None-Match and If-Match sent together answer 412.

Also corrects a paragraph #375 left true-when-written and false-on-merge.
It said "#373's fix plan also called for deleting a .golangci.yml exclusion
for debug_mode_test.go. There is no such exclusion" — accurate when #375 was
cut, but #374 added that exclusion, and merging main into #375 deleted it.
Rewritten to say what actually happened, since the interesting fact is that
merge order decided whether a dead suppression survived.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant