Skip to content

Commit a25160c

Browse files
committed
test(db): close every pool the isolation suite opens
1 parent 171f06e commit a25160c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎apps/sim/lib/db/pool-isolation.integration.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* on their own pools. postgres.js pipelines new work onto busy connections when none is idle, so
55
* anything still on the process pool waits for the lock instead.
66
*/
7-
import { db } from '@sim/db'
7+
import { db, dbFor } from '@sim/db'
88
import { session, user } from '@sim/db/schema'
99
import { readTestDatabaseUrl } from '@sim/db/testing/test-infrastructure'
1010
import { sleep } from '@sim/utils/helpers'
@@ -78,10 +78,18 @@ beforeAll(async () => {
7878
})
7979

8080
afterAll(async () => {
81-
await control`SELECT pg_advisory_unlock(${lockKey})`
82-
await saturation
83-
await db.delete(user).where(eq(user.id, userId))
84-
await control.end()
81+
try {
82+
await control`SELECT pg_advisory_unlock(${lockKey})`
83+
await saturation
84+
await db.delete(user).where(eq(user.id, userId))
85+
} finally {
86+
await Promise.all([
87+
db.$client.end(),
88+
dbFor('billing').$client.end(),
89+
dbFor('auth').$client.end(),
90+
control.end(),
91+
])
92+
}
8593
})
8694

8795
describe('dedicated pools under a saturated process pool', () => {

0 commit comments

Comments
 (0)