Skip to content

test(api): isolate container DB between tests#36310

Merged
asukaminato0721 merged 3 commits into
langgenius:mainfrom
escape0707:test/container-db-isolation-after-session-fixes
May 18, 2026
Merged

test(api): isolate container DB between tests#36310
asukaminato0721 merged 3 commits into
langgenius:mainfrom
escape0707:test/container-db-isolation-after-session-fixes

Conversation

@escape0707
Copy link
Copy Markdown
Contributor

@escape0707 escape0707 commented May 18, 2026

Summary

Part of #32454 (comment). Draft follow-up to #36308.

This adds a central DB isolation fixture for container integration tests. After each test that used the containerized Flask app, the fixture truncates SQLAlchemy application tables and restarts identities.

The cleanup transaction sets SET LOCAL lock_timeout = '5s' so leaked sessions or open transactions fail CI loudly instead of causing a long hang.

Design

  • Function-scoped cleanup: each test may commit freely, but the next test should start from a clean application DB.
  • Autouse fixture does not directly depend on flask_app_with_containers, so tests that do not use the containerized app do not start the full stack just because the cleanup fixture exists.
  • Scope is limited to SQLAlchemy tables in db.metadata; Redis, object storage, and custom ad hoc metadata remain separate cleanup concerns.

Review order

Please review and merge #36308 first. This branch is stacked on top of that service fix branch; after #36308 merges, this PR should reduce to the container DB isolation change.

A diagnostic version of this cleanup is recorded in #36304. That draft intentionally applies the cleanup before the session fixes, so it can expose the existing leaked-session failure mode.

Validation

  • uv run --project api ruff check api/services/attachment_service.py api/services/file_service.py api/tests/test_containers_integration_tests/conftest.py
  • uv run --project api python -m compileall -q api/services/attachment_service.py api/services/file_service.py api/tests/test_containers_integration_tests/conftest.py

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 43.69% +43.69%
Strict coverage 0.00% 43.22% +43.22%
Typed symbols 0 22,136 +22,136
Untyped symbols 0 28,840 +28,840
Modules 0 2558 +2,558

@escape0707 escape0707 marked this pull request as ready for review May 18, 2026 07:23
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 18, 2026
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 18, 2026
@asukaminato0721 asukaminato0721 enabled auto-merge May 18, 2026 08:32
@asukaminato0721 asukaminato0721 added this pull request to the merge queue May 18, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 18, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue May 18, 2026
Merged via the queue into langgenius:main with commit 9dc95ee May 18, 2026
27 checks passed
@escape0707 escape0707 deleted the test/container-db-isolation-after-session-fixes branch May 18, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants