diff --git a/backend/tests/test_discover.py b/backend/tests/test_discover.py index 31566b26..37c9e5d4 100644 --- a/backend/tests/test_discover.py +++ b/backend/tests/test_discover.py @@ -1105,10 +1105,16 @@ def test_two_overlapping_reorders_never_share_a_slot(db, as_user): worker = threading.Thread(target=second_tab) worker.start() - # Commit A only once B is blocked on a row lock, so B's read is the stale snapshot. + # Commit A only once B is blocked on a row lock, so B's read is the stale snapshot. pg_locks is + # the whole server's: only a wait in this database is B's (a parallel worker's is not). waiting = 0 for _ in range(200): - waiting = probe.scalar(text("SELECT count(*) FROM pg_locks WHERE NOT granted")) + waiting = probe.scalar( + text( + "SELECT count(*) FROM pg_locks WHERE NOT granted AND pid IN" + " (SELECT pid FROM pg_stat_activity WHERE datname = current_database())" + ) + ) probe.rollback() if waiting: break diff --git a/backend/tests/test_playlist_sync_claim.py b/backend/tests/test_playlist_sync_claim.py index fb133640..afce741e 100644 --- a/backend/tests/test_playlist_sync_claim.py +++ b/backend/tests/test_playlist_sync_claim.py @@ -89,9 +89,13 @@ def test_a_claim_is_released_when_its_block_raises(db, make_user): except RuntimeError: pass # Asked of pg_locks, not by claiming again: a lock leaked on a pooled connection would be granted - # again to that same connection (advisory locks are re-entrant per session). + # again to that same connection (advisory locks are re-entrant per session). pg_locks is the whole + # server's, so only this database's: a parallel worker's own claim on the same id counted here. held = db.scalar( - text("SELECT count(*) FROM pg_locks WHERE locktype = 'advisory' AND objid = :id"), + text( + "SELECT count(*) FROM pg_locks WHERE locktype = 'advisory' AND objid = :id" + " AND database = (SELECT oid FROM pg_database WHERE datname = current_database())" + ), {"id": pl.id}, ) assert held == 0