Skip to content

Commit 5592926

Browse files
committed
test(db/postgres): isolate withTransaction assertions from the pool bootstrap
1 parent 54fe7d6 commit 5592926

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

test/db/postgres/helper.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,23 @@ describe('PostgreSQL - helper', async () => {
302302
connectionString: 'postgresql://localhost/x',
303303
});
304304

305+
// Warm the pool first so the schema bootstrap's own client activity
306+
// does not blend into the assertions below.
307+
await connect();
308+
mockClientQuery.mockClear();
309+
mockClientRelease.mockClear();
310+
305311
const result = await withTransaction(async (client) => {
306312
await client.query('SELECT 1');
307313
return 'ok';
308314
});
309315

310316
expect(result).toBe('ok');
311-
const statements = mockClientQuery.mock.calls.map(([sql]) => sql);
312-
expect(statements[0]).toBe('BEGIN');
313-
expect(statements).toContain('SELECT 1');
314-
expect(statements[statements.length - 1]).toBe('COMMIT');
317+
expect(mockClientQuery.mock.calls.map(([sql]) => sql)).toEqual([
318+
'BEGIN',
319+
'SELECT 1',
320+
'COMMIT',
321+
]);
315322
expect(mockClientRelease).toHaveBeenCalledTimes(1);
316323
});
317324

@@ -322,15 +329,17 @@ describe('PostgreSQL - helper', async () => {
322329
connectionString: 'postgresql://localhost/x',
323330
});
324331

332+
await connect();
333+
mockClientQuery.mockClear();
334+
mockClientRelease.mockClear();
335+
325336
await expect(
326337
withTransaction(async () => {
327338
throw new Error('boom');
328339
}),
329340
).rejects.toThrow('boom');
330341

331-
const statements = mockClientQuery.mock.calls.map(([sql]) => sql);
332-
expect(statements[0]).toBe('BEGIN');
333-
expect(statements[statements.length - 1]).toBe('ROLLBACK');
342+
expect(mockClientQuery.mock.calls.map(([sql]) => sql)).toEqual(['BEGIN', 'ROLLBACK']);
334343
expect(mockClientRelease).toHaveBeenCalledTimes(1);
335344
});
336345
});

0 commit comments

Comments
 (0)