-
Notifications
You must be signed in to change notification settings - Fork 4k
ci: run PostgreSQL tests in isolated lane #6730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheSentinel454
wants to merge
17
commits into
main
Choose a base branch
from
codex/issue-20-postgres-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,490
−403
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
55f7bb8
ci: add isolated PostgreSQL test lane
TheSentinel454 241a0ec
test: centralize PostgreSQL test URLs
TheSentinel454 dc9349d
ci: guard PostgreSQL test discovery
TheSentinel454 9e67179
docs: remove PostgreSQL CI plans
TheSentinel454 e9e02c0
ci: parse Rust ignore attributes safely
TheSentinel454 66dd31a
ci: address PostgreSQL lane review feedback
TheSentinel454 10a3888
ci: fix PostgreSQL workflow environment scope
TheSentinel454 965e7d9
ci: tighten PostgreSQL integration discovery
TheSentinel454 4bfb31d
ci: derive PostgreSQL lane packages from discovery
TheSentinel454 aad3e72
ci: harden PostgreSQL discovery isolation
TheSentinel454 e0a5184
ci: classify observability PostgreSQL tests
TheSentinel454 5d964b1
test: classify deletion S3 coverage
TheSentinel454 364bf70
ci: invalidate PostgreSQL archive on discovery changes
TheSentinel454 795c169
ci: preserve PostgreSQL discovery after rebase
TheSentinel454 65d14e7
ci: harden PostgreSQL test discovery
TheSentinel454 5e53f83
ci: preserve single-file PostgreSQL discovery
TheSentinel454 8ab6bba
ci: consolidate PostgreSQL test ownership
TheSentinel454 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| nextest-version = "0.9.136" | ||
| # The PostgreSQL lane uses a run-scoped desired-state template database and a | ||
| # per-test wrapper, both of which require nextest's script support. | ||
| experimental = ["setup-scripts", "wrapper-scripts"] | ||
|
|
||
| [scripts.setup.postgres-template] | ||
| # Bootstrap the desired-state source database once per nextest invocation. | ||
| command = { command-line = "scripts/postgres-test-setup.sh", relative-to = "workspace-root" } | ||
| slow-timeout = "60s" | ||
|
|
||
| [scripts.wrapper.postgres-isolation] | ||
| # Clone or create a unique database for each test process, then drop it on exit. | ||
| command = { command-line = "scripts/postgres-test-wrapper.sh", relative-to = "workspace-root" } | ||
|
|
||
| [profile.postgres-ci] | ||
| # This structural convention keeps new PostgreSQL-backed tests discoverable | ||
| # without maintaining an exact list of test names. | ||
| default-filter = """ | ||
| (test(/postgres_tests::/) or binary(/^postgres_/)) | ||
| and not test(/(^|::)external_infra[^:]*::/) | ||
| """ | ||
| fail-fast = false | ||
| # Eight workers was the fastest stable setting in the Blox benchmark while the | ||
| # wrapper retained one database per concurrently running test process. | ||
| test-threads = 8 | ||
|
|
||
| [test-groups.postgres-cluster-global] | ||
| # These tests inspect cluster-wide activity or create least-privilege sessions, | ||
| # so database-per-test isolation alone cannot make them independent. | ||
| max-threads = 1 | ||
|
|
||
| [[profile.postgres-ci.overrides]] | ||
| filter = "test(/cluster_global_/)" | ||
| test-group = "postgres-cluster-global" | ||
|
|
||
| [[profile.postgres-ci.scripts]] | ||
| # Script filters are separate from default-filter: they attach the setup and | ||
| # isolation wrapper to the same automatically discovered test set. | ||
| filter = "(test(/postgres_tests::/) or binary(/^postgres_/)) and not test(/(^|::)external_infra[^:]*::/)" | ||
| setup = "postgres-template" | ||
| run-wrapper = "postgres-isolation" |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # PostgreSQL-backed tests in buzz-db | ||
|
|
||
| The dedicated PostgreSQL CI lane discovers tests and Cargo packages by | ||
| structure rather than by exact lists. Follow this checklist so a new database | ||
| test is run automatically and remains safe under parallel execution. | ||
|
|
||
| ## Adding a test | ||
|
|
||
| 1. Put the test in a module whose name ends in `postgres_tests`. | ||
| 2. Mark it `#[ignore = "requires Postgres"]` so infrastructure-free unit-test | ||
| jobs stay fast. | ||
| 3. Connect through `crate::test_support::database_url()`. The CI wrapper sets | ||
| this helper's environment to a unique database for each test process; never | ||
| hard-code the shared development database. | ||
| 4. Keep tests that need infrastructure beyond PostgreSQL and Redis in an | ||
| `external_infra*_tests` module. The PostgreSQL lane excludes those tests. | ||
| 5. Run `scripts/test-postgres-test-discovery.sh` after adding or moving the | ||
| test. The same guard runs in CI immediately after changed-path detection. | ||
|
|
||
| The wrapper isolates destructive tests by dropping the entire per-test | ||
| database after the process exits. It does not `DELETE` rows or `TRUNCATE` | ||
| shared tables, so tests may run concurrently without coordinating cleanup. | ||
|
|
||
| ## Choose the schema intentionally | ||
|
|
||
| Most tests use the committed desired-state schema from `schema/schema.sql`. | ||
| That is the default and is appropriate for data-access behavior. | ||
|
|
||
| Tests in `migration::postgres_tests` receive an empty database and own the | ||
| embedded migration lifecycle. A test outside that module that intentionally | ||
| depends on migration-created triggers or seed rows must prefix its function | ||
| name with `migration_schema_`; it also receives an empty database with | ||
| `BUZZ_TEST_SCHEMA_MODE=migration`. | ||
|
|
||
| Helpers that normally run migrations honor `BUZZ_TEST_SCHEMA_MODE=desired` in | ||
| the default lane. Do not rerun migrations against a desired-state database. | ||
| When behavior should match in both schema paths, add explicit desired-state and | ||
| migration-applied coverage rather than making the bootstrap implicit. | ||
|
|
||
| Tests that inspect cluster-wide PostgreSQL state or open least-privilege | ||
| sessions include `cluster_global_` in the function name. Migration-backed cases | ||
| use `migration_schema_cluster_global_`. Nextest serializes this small group | ||
| because separate databases still share `pg_stat_activity` and roles. | ||
|
|
||
| ## Run the lane locally | ||
|
|
||
| Start native PostgreSQL and Redis, activate Hermit, and run: | ||
|
|
||
| ```bash | ||
| . ./bin/activate-hermit | ||
| scripts/test-postgres-test-discovery.sh | ||
| scripts/postgres-test-run.sh | ||
| ``` | ||
|
|
||
| Set `BUZZ_POSTGRES_ADMIN_URL` to a PostgreSQL maintenance database owned by a | ||
| role that can create and drop databases. Set `PGHOST`, `PGPORT`, `PGUSER`, and | ||
| `PGPASSWORD` for desired-state bootstrap, plus `REDIS_URL` for Redis-backed | ||
| tests. The complete privilege-boundary inventory also needs `CREATEROLE` and | ||
| membership in `pg_read_all_stats`, or an ephemeral superuser as CI uses. | ||
|
|
||
| The runner creates one desired-state source database per invocation and clones | ||
| it for ordinary tests. Migration-mode tests start empty. Cleanup retries | ||
| transient disconnect races before reporting a warning. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1041,4 +1041,5 @@ impl Db { | |
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; | ||
| #[path = "tests.rs"] | ||
| mod postgres_tests; | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.