Skip to content

test(db): run the Postgres package's suites in parallel on free ports - #713

Merged
fclairamb merged 1 commit into
mainfrom
fix/postgres-tests-parallel
Oct 30, 2026
Merged

fclairamb merged 1 commit into
mainfrom
fix/postgres-tests-parallel

Conversation

@fclairamb

Copy link
Copy Markdown
Owner

Fixes the red Backend Postgres Tests job on main (run 40973235887).

Cause

internal/db/postgres hit go test's default 10-minute per-package timeout. Its ~107 tests each boot an embedded PostgreSQL and run every migration, almost all of them serially (~624s total). Green runs had already crept up from 413s to 566s. The failing commit didn't touch this package; it just tipped it over the limit.

Fix

  • New testsupport.FreePort(t): a port assigned by the kernel and deduplicated in-process. It comes from the ephemeral range, so it can't clash with the 14xxx/15xxx fixed ports other packages use.
  • Every test in the package uses it in place of a hard-coded port constant (same-file tests used to share one), and calls t.Parallel().
  • The old nolint:paralleltest reason ("pwfile extraction race") no longer holds: embeddedpg gives each instance its own runtime dir.
  • Still serial: the 5 headroom tests that swap the global slog default, and the subtests of TestGetLastSignalForChecks_Postgres, which share one instance in order.

Verification

  • Locally: SP_TEST_REQUIRE_POSTGRES=1 go test -parallel 4 ./internal/db/postgres/ passes in 78s, 0 skips.
  • golangci-lint run on the touched packages: 0 issues.

🤖 Generated with Claude Code

The Backend Postgres Tests job failed on main (run 40973235887): the
internal/db/postgres package hit go test's default 10-minute timeout. Its
~107 tests each boot an embedded PostgreSQL and run every migration, almost
all of them one after another, for ~624s of serial time. Green runs had
already crept from 413s to 566s; nothing in the failing commit touched it.

Every test now asks testsupport.FreePort for a kernel-assigned port (deduped
in-process) instead of a hand-numbered constant that same-file tests shared,
and calls t.Parallel(). The "pwfile extraction" reason on the old
nolint:paralleltest directives no longer holds: embeddedpg gives each
instance its own runtime directory. The five headroom tests that swap the
global slog default stay serial.

Locally the package now runs in 78s at -parallel 4, with no skips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.75%. Comparing base (208ff0a) to head (2eda961).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/internal/testsupport/port.go 70.58% 5 Missing ⚠️

❌ Your patch status has failed because the patch coverage (70.58%) is below the target coverage (87.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #713      +/-   ##
==========================================
- Coverage   89.76%   89.75%   -0.01%     
==========================================
  Files        1296     1297       +1     
  Lines      132198   132215      +17     
==========================================
+ Hits       118672   118676       +4     
- Misses      13517    13530      +13     
  Partials        9        9              
Files with missing lines Coverage Δ
server/internal/testsupport/port.go 70.58% <70.58%> (ø)

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fclairamb
fclairamb merged commit 7d346c6 into main Oct 30, 2026
33 of 34 checks passed
@fclairamb
fclairamb deleted the fix/postgres-tests-parallel branch October 30, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant