Support parallel test runs in external-schema mode#3512
Conversation
The backwards-compatibility CI check runs a previous release's `-m db` test suite against a schema built by the current code, using external-schema mode (`PALACE_TEST_DATABASE_EXTERNAL_SCHEMA=true`). Until now that mode used the one configured database as-is and forbade xdist, so the suite had to run serially (`-n0`) and took ~13 minutes. Make external-schema mode parallel-capable: when database creation is enabled (the default), each worker now provisions its own database by cloning the configured database as a Postgres template (`CREATE DATABASE ... TEMPLATE`). The previous release's tests still run against the schema the current code produced, but each worker gets an isolated database, so the suite can run under xdist. Admin (CREATE/DROP DATABASE) operations now connect to the `postgres` maintenance database rather than the configured one, since you cannot clone a template you are connected to; these are cluster-level commands that work from any database, and this path is exercised by the normal suite on every run. The single-shared-database serial mode (external schema with database creation disabled) is preserved for local debugging.
|
Claude finished @jonathangreen's task in 2m 8s —— View job Claude Code Review
SummaryThis is a clean, well-scoped change confined to the test fixture layer. The template-clone approach ( Note on the prior reviewThe Greptile P1 ("Missing None guard for template database name") has already been addressed by commit |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3512 +/- ##
=======================================
Coverage 93.44% 93.44%
=======================================
Files 511 511
Lines 46468 46468
Branches 6340 6340
=======================================
Hits 43423 43423
Misses 1969 1969
Partials 1076 1076 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
In external-schema mode the configured database is used as the clone template. If the configured URL omits a database component, the previous code would emit `CREATE DATABASE foo TEMPLATE None` and fail with an obscure PostgreSQL error. Validate at fixture setup that the URL names a database, raising a descriptive BasePalaceException instead.
Fix a typo and use "worker" rather than "thread" (xdist runs separate worker processes), and tidy the wording describing how each worker's database is populated in normal vs. external-schema mode.
Description
Makes the test suite's external-schema mode parallel-capable. When database creation is enabled (the default), each xdist worker now provisions its own database by cloning the configured database as a Postgres template (
CREATE DATABASE ... TEMPLATE), instead of all workers sharing the one configured database. The previous release's tests still run against the schema the current code produced, but each worker gets an isolated database, so the suite can run under xdist.Admin (
CREATE/DROP DATABASE) operations now connect to thepostgresmaintenance database rather than the configured one, since you cannot clone a template you are connected to; these are cluster-level commands that work from any database, and this path is exercised by the normal suite on every run.The single-shared-database serial mode (external schema with database creation disabled) is preserved for local debugging.
Motivation and Context
The backwards-compatibility CI check runs a previous release's
-m dbtest suite against a schema built by the current code, using external-schema mode. Until now that mode used the one configured database as-is and forbade xdist, so the suite ran serially (-n0) and took ~13 minutes. Its not really feasible for this check to take so long, so I'm adding this option to speed it up.This will have to be merged and go into a release, before I can test it in the workflow in #3506
How Has This Been Tested?
Because the backwards-compatibility job won't exercise this for real until the next release, it was proven locally:
-n autowithPALACE_TEST_DATABASE_EXTERNAL_SCHEMA=true/PALACE_TEST_DATABASE_CREATE_DATABASE=true; per-workersession_gw*clones were created from the template and dropped at teardown.UndefinedTable, confirming the check still catches backwards-incompatible schemas under parallelism.postgresmaintenance database on every run) passed viatox -e py312-docker.-n auto, clone-per-worker): 3,269 db tests passed in 3:47 on a 4-worker runner, versus ~13 minutes serial.mypyclean.Checklist