Add concurrent role creation test demonstrating race condition (intentionally fails on main) #327
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.
Add concurrent role creation test (reproduces unique_violation bug)
Summary
This PR adds a comprehensive test suite that intentionally demonstrates the race condition in concurrent PostgreSQL role creation on the main branch. The test should FAIL on main and PASS on the fix branches (PR #325 and PR #326).
Key Changes:
packages/pgsql-test/__tests__/postgres-test.concurrent-roles.test.tsThe Bug Being Demonstrated:
When multiple processes attempt to create the same PostgreSQL role simultaneously, the current code only catches
duplicate_objectexceptions. However, under concurrency, the actual error isunique_violation(error code 23505) when both sessions race to insert intopg_authidand hit thepg_authid_rolname_indexunique constraint.Test Cases:
Review & Testing Checklist for Human
CRITICAL - This PR is expected to FAIL on main branch:
should handle concurrent role creation without errors) actually FAILS on main with aunique_violationerrorTest Plan:
Notes
Related PRs:
Why this test is valuable:
Potential Issues:
Session Info: