diff --git a/src/index.ts b/src/index.ts index 551ff51..25ba576 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,14 +72,21 @@ export const getTestPostgresDatabaseFactory = < connectionDetailsFromWorker: ConnectionDetailsFromWorker ): ConnectionDetails => { const pool = new Pool({ - connectionString: - connectionDetailsFromWorker.pgbouncerConnectionString ?? - connectionDetailsFromWorker.connectionString, + connectionString: connectionDetailsFromWorker.connectionString, }) + let pgbouncerPool: Pool | undefined + if (connectionDetailsFromWorker.pgbouncerConnectionString) { + pgbouncerPool = new Pool({ + connectionString: + connectionDetailsFromWorker.pgbouncerConnectionString, + }) + } + t.teardown(async () => { try { await pool.end() + await pgbouncerPool?.end() } catch (error) { if ( (error as Error).message.includes( @@ -96,6 +103,7 @@ export const getTestPostgresDatabaseFactory = < return { ...connectionDetailsFromWorker, pool, + pgbouncerPool, } } diff --git a/src/public-types.ts b/src/public-types.ts index 68f1e1b..d2bbd57 100644 --- a/src/public-types.ts +++ b/src/public-types.ts @@ -18,6 +18,9 @@ export interface ConnectionDetails { database: string pool: Pool + + // TODO if pgbouncer is enabled, this is defined, otherwise undefined + pgbouncerPool?: Pool } export interface GetTestPostgresDatabaseFactoryOptions< diff --git a/src/tests/pgbouncer.test.ts b/src/tests/pgbouncer.test.ts index 0a72e26..8bd26ed 100644 --- a/src/tests/pgbouncer.test.ts +++ b/src/tests/pgbouncer.test.ts @@ -20,7 +20,9 @@ test("pgbouncer", async (t) => { t.is(result.rows[0].result, 1) // can't use a transaction with statement pool mode - const err = await t.throwsAsync(postgres13.pool.query(`BEGIN TRANSACTION`)) + const err = await t.throwsAsync( + postgres13.pgbouncerPool!.query(`BEGIN TRANSACTION`) + ) t.truthy( err!