Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v35.0.2
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v35.0.3
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 27, 2023

  1. Copy the full SHA
    8f066eb View commit details
Showing with 29 additions and 0 deletions.
  1. +10 −0 src/factories/createPool.ts
  2. +19 −0 test/helpers/createIntegrationTests.ts
10 changes: 10 additions & 0 deletions src/factories/createPool.ts
Original file line number Diff line number Diff line change
@@ -72,6 +72,16 @@ export const createPool = async (
},
});

// https://github.com/gajus/slonik/issues/471
pool.on('error', (error) => {
poolLog.error(
{
error: serializeError(error),
},
'client error',
);
});

poolStateMap.set(pool, {
ended: false,
mock: false,
19 changes: 19 additions & 0 deletions test/helpers/createIntegrationTests.ts
Original file line number Diff line number Diff line change
@@ -140,6 +140,25 @@ export const createIntegrationTests = (
test: TestFn<TestContextType>,
PgPool: new () => PgPoolType,
) => {
test('properly handles terminated connections', async (t) => {
const pool = await createPool(t.context.dsn, {
PgPool,
});

await Promise.all([
pool.connect(() => Promise.resolve()),
pool.connect(() => Promise.resolve()),
]);

await t.notThrowsAsync(
pool.query(sql.unsafe`
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid != pg_backend_pid()
`),
);
});

test('produces syntax error with the original SQL', async (t) => {
const pool = await createPool(t.context.dsn, {
PgPool,