test(api): isolate container DB between tests#36304
Closed
escape0707 wants to merge 1 commit into
Closed
Conversation
Contributor
Pyrefly Type Coverage
|
Contributor
Author
|
Diagnostic result recorded. This draft PR proved the intended failure mode: enabling central container DB cleanup before the service session fixes makes API Integration Tests fail loudly during cleanup instead of hanging. Evidence from CI: The job completed with Follow-up PRs:
|
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.
Summary
Part of #32454 (comment).
This is a diagnostic draft PR. It is expected to expose existing DB session leaks before the service fixes are applied.
The code change is the intended test infrastructure direction: after each container integration test that used the containerized Flask app, reset SQLAlchemy application tables with
TRUNCATE ... RESTART IDENTITY CASCADE.The cleanup also sets
SET LOCAL lock_timeout = '5s'for the cleanup transaction. That is test-only behavior inconftest.py: if another session is holding a conflicting lock, CI should fail loudly instead of hanging for a long time.Why this exists
Container integration tests currently share one PostgreSQL container and many tests/services commit through different sessions. Without a central cleanup contract, DB state can leak between tests unless each test adds its own local cleanup workaround.
This draft PR records what happens when central DB isolation is enabled before fixing the existing session leaks. The follow-up service PR should close the leaked private sessions, and the final DB isolation PR should build on that.
Validation
uv run --project api ruff check api/tests/test_containers_integration_tests/conftest.py