Comparing version 39.1.1 to 39.2.0
@@ -98,2 +98,4 @@ "use strict"; | ||
} | ||
await query('DISCARD ALL'); | ||
// eslint-disable-next-line require-atomic-updates | ||
isActive = false; | ||
@@ -100,0 +102,0 @@ if (clientConfiguration.idleTimeout !== 'DISABLE_TIMEOUT') { |
@@ -1194,4 +1194,123 @@ "use strict"; | ||
}); | ||
test('re-uses connections (implicit)', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('re-uses connections (explicit)', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
let firstConnectionPid; | ||
await pool.connect(async (connection) => { | ||
firstConnectionPid = await connection.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
let secondConnectionPid; | ||
await pool.connect(async (connection) => { | ||
secondConnectionPid = await connection.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('re-uses connections (transaction)', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
let firstConnectionPid; | ||
await pool.transaction(async (transaction) => { | ||
firstConnectionPid = await transaction.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
let secondConnectionPid; | ||
await pool.transaction(async (transaction) => { | ||
secondConnectionPid = await transaction.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('queues requests when the pool is full', async (t) => { | ||
t.timeout(10000); | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const startTime = Date.now(); | ||
await Promise.all([ | ||
await pool.query(__1.sql.unsafe ` | ||
SELECT pg_sleep(0.1) | ||
`), | ||
await pool.query(__1.sql.unsafe ` | ||
SELECT pg_sleep(0.1) | ||
`), | ||
]); | ||
t.true(Date.now() - startTime >= 200); | ||
}); | ||
test('does not re-use connection if there was an error', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
await t.throwsAsync(pool.query(__1.sql.unsafe ` | ||
SELECT 1 / 0; | ||
`)); | ||
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.not(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('does not re-use transaction connection if there was an error', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
await t.throwsAsync(pool.transaction(async (transaction) => { | ||
await transaction.query(__1.sql.unsafe ` | ||
SELECT 1 / 0; | ||
`); | ||
})); | ||
const secondConnectionPid = await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.not(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('connections are reset after they are released', async (t) => { | ||
const pool = await (0, __1.createPool)(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
await pool.connect(async (connection) => { | ||
await connection.query(__1.sql.unsafe ` | ||
SET slonik.foo = 'bar'; | ||
`); | ||
t.is(await connection.oneFirst(__1.sql.unsafe ` | ||
SELECT current_setting('slonik.foo'); | ||
`), 'bar'); | ||
}); | ||
t.is(await pool.oneFirst(__1.sql.unsafe ` | ||
SELECT current_setting('slonik.foo'); | ||
`), ''); | ||
}); | ||
}; | ||
exports.createIntegrationTests = createIntegrationTests; | ||
//# sourceMappingURL=createIntegrationTests.js.map |
@@ -97,3 +97,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "39.1.1" | ||
"version": "39.2.0" | ||
} |
@@ -185,2 +185,5 @@ import { type ClientConfiguration, type TypedReadable } from '../types'; | ||
await query('DISCARD ALL'); | ||
// eslint-disable-next-line require-atomic-updates | ||
isActive = false; | ||
@@ -187,0 +190,0 @@ |
@@ -1562,2 +1562,166 @@ /* eslint-disable id-length */ | ||
}); | ||
test('re-uses connections (implicit)', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
const secondConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('re-uses connections (explicit)', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
let firstConnectionPid: number | undefined; | ||
await pool.connect(async (connection) => { | ||
firstConnectionPid = await connection.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
let secondConnectionPid: number | undefined; | ||
await pool.connect(async (connection) => { | ||
secondConnectionPid = await connection.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('re-uses connections (transaction)', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
let firstConnectionPid: number | undefined; | ||
await pool.transaction(async (transaction) => { | ||
firstConnectionPid = await transaction.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
let secondConnectionPid: number | undefined; | ||
await pool.transaction(async (transaction) => { | ||
secondConnectionPid = await transaction.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
}); | ||
t.is(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('queues requests when the pool is full', async (t) => { | ||
t.timeout(10_000); | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const startTime = Date.now(); | ||
await Promise.all([ | ||
await pool.query(sql.unsafe` | ||
SELECT pg_sleep(0.1) | ||
`), | ||
await pool.query(sql.unsafe` | ||
SELECT pg_sleep(0.1) | ||
`), | ||
]); | ||
t.true(Date.now() - startTime >= 200); | ||
}); | ||
test('does not re-use connection if there was an error', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
await t.throwsAsync( | ||
pool.query(sql.unsafe` | ||
SELECT 1 / 0; | ||
`), | ||
); | ||
const secondConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.not(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('does not re-use transaction connection if there was an error', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
const firstConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
await t.throwsAsync( | ||
pool.transaction(async (transaction) => { | ||
await transaction.query(sql.unsafe` | ||
SELECT 1 / 0; | ||
`); | ||
}), | ||
); | ||
const secondConnectionPid = await pool.oneFirst(sql.unsafe` | ||
SELECT pg_backend_pid(); | ||
`); | ||
t.not(firstConnectionPid, secondConnectionPid); | ||
}); | ||
test('connections are reset after they are released', async (t) => { | ||
const pool = await createPool(t.context.dsn, { | ||
driver, | ||
maximumPoolSize: 1, | ||
}); | ||
await pool.connect(async (connection) => { | ||
await connection.query(sql.unsafe` | ||
SET slonik.foo = 'bar'; | ||
`); | ||
t.is( | ||
await connection.oneFirst(sql.unsafe` | ||
SELECT current_setting('slonik.foo'); | ||
`), | ||
'bar', | ||
); | ||
}); | ||
t.is( | ||
await pool.oneFirst(sql.unsafe` | ||
SELECT current_setting('slonik.foo'); | ||
`), | ||
'', | ||
); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1023104
17990