feat(postgres): add locking attribute to #[sqlx::test]#4180
Open
mpecan wants to merge 1 commit intolaunchbadge:mainfrom
Open
feat(postgres): add locking attribute to #[sqlx::test]#4180mpecan wants to merge 1 commit intolaunchbadge:mainfrom
mpecan wants to merge 1 commit intolaunchbadge:mainfrom
Conversation
014bb58 to
3cf761a
Compare
3cf761a to
501cd1a
Compare
Add a `locking` parameter to `#[sqlx::test]` that controls whether an advisory lock is acquired before creating the test database schema. Defaults to `true` to preserve existing PostgreSQL behavior. Setting `locking = false` allows `#[sqlx::test]` to work with databases that speak the PostgreSQL wire protocol but do not implement advisory locks, such as CockroachDB. When disabled, migrator locking is also skipped so the entire test setup is advisory-lock-free. Follows the same pattern as `Migrator::set_locking()` (PR launchbadge#2063).
501cd1a to
82f2933
Compare
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.
Adds
locking = falsesupport to#[sqlx::test]to skip advisory locks during test database setup and migrations. This is the#[sqlx::test]analog ofMigrator::set_locking(false)(#2063).Since #3753 switched test setup to
pg_advisory_xact_lock, databases that speak the PostgreSQL wire protocol but don't implement advisory locks (e.g. CockroachDB) cannot use#[sqlx::test]at all.Usage:
Locking remains enabled by default. Disabling it means concurrent test runs may race during schema setup, which is acceptable for databases that handle schema DDL differently.
Does your PR solve an issue?
Partially addresses #198 (CockroachDB support).
Is this a breaking change?
No. Default behavior is unchanged (locking = true).