Repository navigation
Clone per-test Postgres databases from a template to fix Go server test timeout - #20700
Merged
Merged
Conversation
…edundant fixtures Since the SQLite removal, every testutil.Postgres fixture provisions a full canonical store (~360 daily partitions, ~5s), pushing internal/server past the 10m go test timeout. Provision one template database per test process through the production store and clone it per test (CREATE DATABASE ... TEMPLATE), falling back to a private schema when the role cannot create databases. Reclaim databases left by exited processes. Also share one app across TestSessionArchiveResponseClosesReader subtests and stop re-executing repository queries already covered by the full dashboard corpus test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
pelikhan
marked this pull request as ready for review
November 12, 2026 18:29
…r-test-timeout # Conflicts: # server/internal/testutil/pgtemplate/pgtemplate.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"Go unit tests (http, shard 0)" in
cgo.ymltimes out after 10 minutes inserver/internal/server, on both PRs and main. The SQLite removal (#20668) made everytestutil.Postgresfixture provision a full canonical store: about 360 daily partitions in about 90 DDL transactions, roughly 5s per test. With 489 tests, the package runs past the timeout. No test hangs, and the CI split in #20689 is not the cause.Approach
server/internal/testutil/pgtemplatepackage.postgresx.NewConfig).CREATE DATABASE ... TEMPLATE, so tests stay isolated.postgresx's own package tests can use it without an import cycle.testutil.PostgresWithConfigpostgresx'snativeTestStorecollectsubprocess tests now receive the clone's DSN (CAO_NATIVE_*_CANONICAL_DSN) when they reopen the canonical store.TestSessionArchiveResponseClosesReader: the six subtests share one app.TestRepositoryQueriesUsePostgres: now only checks that the eight repository queries are in the deployed corpus, sinceTestDashboardQueryCorpusUsesPostgresalready executes the full corpus.Results
Measured locally with
-p 1(as in CI) against postgres:16.internal/serverinternal/postgresxMost of the remaining
postgresxtime is production publication cost (about 0.6s per publication), not setup.These packages pass:
internal/server,postgresx,collect,collectnative,simulator,adxingest,dashboardstore,cmd/cao-dashboardandtestutil/.... No workflow YAML changed.Review notes
contract-matchrather thanfresh-schema; no test depends on that difference.schemaTestSchemastill exercises fresh initialization directly.DROP DATABASE ... WITH (FORCE)requires PG13+; CI uses postgres:16.-p > 1) can exhaust the shared lock table, because dashboard queries lock every daily partition. Raisingmax_locks_per_transaction(for example to 512) fixes it, and the package doc notes this. CI runs with-p 1.TestPostgresRuntimePrivilegeBoundaryfailed once locally in a full run, then passed on every repeat (including-count=8). It uses a separate roles fixture this change does not touch, so it looks like a rare pre-existing flake.