Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions newsfragments/+deflake-terminate-connection.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Scope the ``test_postgres_terminate_connection`` (and async) connection check
to the test's own database via ``datname = current_database()``.

So a transient, already-closed janitor connection on the ``postgres`` maintenance
database no longer causes spurious timeouts on macOS CI.
8 changes: 6 additions & 2 deletions tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_postgres_terminate_connection(postgresql2: Connection, _: int) -> None:
with postgresql2.cursor() as cur:

def check_if_one_connection() -> None:
cur.execute("SELECT * FROM pg_stat_activity WHERE backend_type = 'client backend';")
cur.execute(
"SELECT * FROM pg_stat_activity WHERE backend_type = 'client backend' AND datname = current_database();"
)
existing_connections = cur.fetchall()
assert len(existing_connections) == 1, f"there is always only one connection, {existing_connections}"

Expand Down Expand Up @@ -120,7 +122,9 @@ async def test_postgres_terminate_connection_async(postgresql2_async: AsyncConne
async with postgresql2_async.cursor() as cur:

async def check_if_one_connection() -> None:
await cur.execute("SELECT * FROM pg_stat_activity WHERE backend_type = 'client backend';")
await cur.execute(
"SELECT * FROM pg_stat_activity WHERE backend_type = 'client backend' AND datname = current_database();"
)
existing_connections = await cur.fetchall()
assert len(existing_connections) == 1, f"there is always only one connection, {existing_connections}"

Expand Down
Loading