Skip to content

Commit b7df77c

Browse files
cheddarfoxclaude
andcommitted
fix: use NullPool for asyncpg to prevent E2E connection conflicts [REN-140]
E2E Docker tests fail with "cannot perform operation: another operation is in progress" because asyncpg shares connections across async test fixtures via the default connection pool. Using NullPool gives each test its own connection, eliminating the concurrency conflict. SQLite tests are unaffected (they use the default StaticPool). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 87fcae6 commit b7df77c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎tests/conftest.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
async_sessionmaker,
6161
create_async_engine,
6262
)
63+
from sqlalchemy.pool import NullPool
6364

6465
from core.auth.jwt import create_access_token
6566
from core.database import Base, get_db_session
@@ -86,13 +87,18 @@
8687
@pytest.fixture(scope="session")
8788
async def test_engine():
8889
"""Create a session-scoped async engine and bootstrap the schema."""
89-
engine = create_async_engine(TEST_DATABASE_URL, echo=False)
90+
_is_sqlite = TEST_DATABASE_URL.startswith("sqlite")
91+
92+
# Use NullPool for PostgreSQL/asyncpg to prevent "another operation is in
93+
# progress" errors caused by connection sharing across async test fixtures.
94+
# SQLite uses StaticPool (single in-memory connection shared across tests).
95+
pool_kwargs = {} if _is_sqlite else {"poolclass": NullPool}
96+
engine = create_async_engine(TEST_DATABASE_URL, echo=False, **pool_kwargs)
9097

9198
# When running against PostgreSQL (CI), Alembic migrations have already
9299
# created the schema (including PostgreSQL-specific ENUM types). Calling
93100
# metadata.create_all on top of that causes "type already exists" errors.
94101
# Only bootstrap via create_all for SQLite (unit tests).
95-
_is_sqlite = TEST_DATABASE_URL.startswith("sqlite")
96102

97103
if _is_sqlite:
98104
async with engine.begin() as conn:

0 commit comments

Comments
 (0)