Something went wrong. Try again.
Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
Something went wrong. Try again.
846 B · 34 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435import { describe, expect, test } from 'bun:test'import { type ClosableDatabasePool, createDatabasePoolCloser } from './db'
describe('database pool closer', () => { test('ends the pool once across repeated calls', async () => { let endCalls = 0 const pool: ClosableDatabasePool = { async end() { endCalls++ }, } const close = createDatabasePoolCloser(pool)
const firstClose = close() const secondClose = close() expect(firstClose).toBe(secondClose) await Promise.all([firstClose, secondClose]) await close()
expect(endCalls).toBe(1) })
test('reports a failed close instead of throwing', async () => { let reported = 0 const pool: ClosableDatabasePool = { async end() { throw new Error('boom') }, }
await createDatabasePoolCloser(pool, () => reported++)() expect(reported).toBe(1) })})