Skip to content

Commit c27a994

Browse files
NathanFlurryclaude
andcommitted
feat: US-022 - Add pg-pool e2e-docker fixture for connection pooling
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d194a6 commit c27a994

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"entry": "src/index.js",
3+
"expectation": "pass",
4+
"services": ["postgres"]
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "e2e-docker-pg-pool",
3+
"private": true,
4+
"type": "commonjs",
5+
"dependencies": {
6+
"pg": "8.13.1"
7+
}
8+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const { Pool } = require("pg");
2+
3+
async function main() {
4+
const pool = new Pool({
5+
host: process.env.PG_HOST,
6+
port: Number(process.env.PG_PORT),
7+
user: "testuser",
8+
password: "testpass",
9+
database: "testdb",
10+
max: 5,
11+
});
12+
13+
// Setup
14+
await pool.query(
15+
"CREATE TABLE IF NOT EXISTS test_pool (id SERIAL PRIMARY KEY, value TEXT)",
16+
);
17+
18+
// Acquire client, query, release
19+
const client = await pool.connect();
20+
await client.query("INSERT INTO test_pool (value) VALUES ($1)", [
21+
"from-client",
22+
]);
23+
const clientRes = await client.query(
24+
"SELECT value FROM test_pool WHERE value = $1",
25+
["from-client"],
26+
);
27+
client.release();
28+
29+
// pool.query() shorthand
30+
await pool.query("INSERT INTO test_pool (value) VALUES ($1)", [
31+
"from-shorthand",
32+
]);
33+
const shorthandRes = await pool.query(
34+
"SELECT value FROM test_pool WHERE value = $1",
35+
["from-shorthand"],
36+
);
37+
38+
// Concurrent queries via pool.query()
39+
const [r1, r2, r3] = await Promise.all([
40+
pool.query("SELECT 1 AS n"),
41+
pool.query("SELECT 2 AS n"),
42+
pool.query("SELECT 3 AS n"),
43+
]);
44+
45+
// Cleanup
46+
await pool.query("DROP TABLE test_pool");
47+
await pool.end();
48+
49+
console.log(
50+
JSON.stringify({
51+
connected: true,
52+
clientAcquire: {
53+
rowCount: clientRes.rowCount,
54+
value: clientRes.rows[0].value,
55+
},
56+
shorthand: {
57+
rowCount: shorthandRes.rowCount,
58+
value: shorthandRes.rows[0].value,
59+
},
60+
concurrent: [r1.rows[0].n, r2.rows[0].n, r3.rows[0].n],
61+
}),
62+
);
63+
}
64+
65+
main().catch((err) => {
66+
console.error(err.message);
67+
process.exit(1);
68+
});

0 commit comments

Comments
 (0)