Repository navigation
#122 test: a cancelled request releases its DB session - #130
Merged
Merged
Conversation
Drives the real get_db_session (the client fixtures override it) through a blocking route on the app's own engine, reset to the test database, and asserts pool.checkedout() returns to baseline after a task cancellation and after an http.disconnect as uvicorn delivers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #122
Tests only (
tests/api/test_deps.py). No deploy:drift.counts()ignorestests/.What
real_enginefixture: the app's own engine (reset_engine()+get_engine()onTEST_DATABASE_URL), disposed and reset in teardown. This exercises the realget_db_session, not theclientfixtures' savepointed override.Depends(get_db_session)that runsSELECT 1(sessions check out lazily) and then blocks on anasyncio.Event.test_a_cancelled_request_releases_its_session): underASGITransportthe app runs in the client's task. The test cancels the task while the handler is inside, then assertspool.checkedout()is back to baseline. This is the path 🐛 Fix async yield dependency cleanup on cancellation fastapi/fastapi#16739 (0.162.7) changed.test_a_request_whose_client_disconnected_releases_its_session): this drives raw ASGI.receiveanswershttp.disconnectandsenddrops the response. That matches uvicorn's h11 cycle (connection_lostsetsdisconnected, andsendreturns early). uvicorn doesn't cancel the app task on a disconnect, so the handler runs to completion. The test then asserts the pool is back to baseline.checkedout() == baseline + 1while the handler is blocked, so a session that never checks out a connection can't make it pass.Evidence
test_deps.pypass. Full suite: 1990 passed, 12 skipped, 98.80% coverage. ruff clean.async withand never closes it fails both tests at the final assertion (assert 1 == 0). That change was temporary and isn't committed.uv run --no-sync --with fastapi==0.162.0(fastapi 0.162.0, starlette 1.7.0, no lock change): both pass. So 0.162.0 didn't leak on this path either.🤖 Generated with Claude Code