Keep the browser tests' database in a file, a connection per request (#1024) #1074
No reviewers
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo!1074
Loading…
Reference in a new issue
No description provided.
Delete branch "1024-live-server-db"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On an in-memory SQLite database pytest-django's live server hands the test
thread's one connection to every request thread, and every request is a
transaction (ATOMIC_REQUESTS). Requests in flight at once tangled their
transactions in that one wrapper's bookkeeping: a commit took away another
request's savepoint, and the browser job failed at random with "no such
savepoint" and then a TransactionManagementError on every request and
teardown after it.
A run with an e2e test in it now gives the test database a file of its own
(django_db_modify_db_settings in tests/conftest.py), one per xdist worker in
a temporary directory removed at the end, opened with the instance's own
options (IMMEDIATE transactions, WAL, a 20-second busy timeout; #206), so a
second writer waits its turn. pytest-django shares only in-memory
connections, so each request thread connects for itself. The live server
now waits for the test database (tests/e2e/conftest.py): the font check
started it first, while the connection still named :memory:, and it shared
the connection all the same. The unit suite and a PostgreSQL run are left
as they were.
tests/e2e/test_live_server_connections.py plays the failing order out with
three requests and a pause held open between SAVEPOINT and Django noting it
down; it failed with the CI's errors before the change and passes after.
Closes #1024
Notes for review
Root cause: pytest-django builds
connections_overridewhen the live server starts. The autouse font check started the server beforedjango_db_setup, while the database was still:memory:, so every request thread used the test thread's own connection. WithATOMIC_REQUESTS, the savepoints of overlapping requests got released by the wrong thread: "no such savepoint", then aTransactionManagementErrorcascade (1,829 errors in one CI run).Fix:
live_servernow depends ondjango_db_setup, so the override is empty.Regression test:
tests/e2e/test_live_server_connections.pyreproduces the failure deterministically (failed before the fix, passes after) and asserts the override is empty.Timings, each file alone, run twice, in seconds:
test_reflowtest_every_pagetest_accessibilityNot yet run: with
-n, where the per-worker file is reasoned from pytest-django's source. That arrives with #1033's second worker.🤖 Generated with Claude Code
241bbf93b7ece1170f6aece1170f6a9691831204