diff --git a/graphql/server/__tests__/schema.test.ts b/graphql/server/__tests__/schema.test.ts index 2d9be7013..4bced4d96 100644 --- a/graphql/server/__tests__/schema.test.ts +++ b/graphql/server/__tests__/schema.test.ts @@ -37,8 +37,8 @@ afterAll(async () => { await new Promise((resolve) => server!.close(() => resolve())); server = null; } - await teardown(); await closePgPools(); + await teardown(); }); beforeEach(async () => { diff --git a/postgres/pgsql-client/src/client.ts b/postgres/pgsql-client/src/client.ts index 482f9ab62..b3dca6553 100644 --- a/postgres/pgsql-client/src/client.ts +++ b/postgres/pgsql-client/src/client.ts @@ -46,7 +46,7 @@ export class PgClient { if (!this._ended) { this._ended = true; await this.ensureConnected(); - this.client.end(); + await this.client.end(); } } diff --git a/postgres/pgsql-test/src/manager.ts b/postgres/pgsql-test/src/manager.ts index 466e5ea30..b5f562546 100644 --- a/postgres/pgsql-test/src/manager.ts +++ b/postgres/pgsql-test/src/manager.ts @@ -9,13 +9,13 @@ const log = new Logger('test-connector'); const SYS_EVENTS = ['SIGTERM']; -const end = (pool: Pool) => { +const end = async (pool: Pool): Promise => { try { if ((pool as any).ended || (pool as any).ending) { log.warn('⚠️ pg pool already ended or ending'); return; } - pool.end(); + await pool.end(); } catch (err) { log.error('❌ pg pool termination error:', err); } @@ -123,11 +123,13 @@ export class PgTestConnector { this.clients.clear(); log.info('🧯 Disposing pg pools...'); + const poolTasks: Promise[] = []; for (const [key, pool] of this.pgPools.entries()) { log.debug(`🧯 Disposing pg pool [${key}]`); - end(pool); + poolTasks.push(end(pool)); } this.pgPools.clear(); + await Promise.allSettled(poolTasks); if (keepDb) { log.info('📦 Keeping databases (keepDb=true)...');