Skip to content

Commit acd8b70

Browse files
committed
test: add test for /issues/3148
1 parent 203ee72 commit acd8b70

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const createPool = require('../common.test.cjs').createPool;
3+
const { assert } = require('poku');
4+
5+
/**
6+
* This test case tests that the pool releases connections gracefully after the idle timeout has passed.
7+
*
8+
* @see https://github.com/sidorares/node-mysql2/issues/3148
9+
*/
10+
11+
const pool = new createPool({
12+
connectionLimit: 3,
13+
maxIdle: 2,
14+
idleTimeout: 1000,
15+
});
16+
17+
let connection1Ended = false;
18+
let connection2Ended = false;
19+
let connection3Ended = false;
20+
21+
pool.getConnection((_err1, connection1) => {
22+
pool.getConnection((_err2, connection2) => {
23+
pool.getConnection((_err3, connection3) => {
24+
connection1.stream.on('end', () => (connection1Ended = true));
25+
connection2.stream.on('end', () => (connection2Ended = true));
26+
connection3.stream.on('end', () => (connection3Ended = true));
27+
28+
connection1.release();
29+
connection2.release();
30+
connection3.release();
31+
32+
setTimeout(() => {
33+
assert(connection1Ended, 'connection1 should have ended');
34+
assert(connection2Ended, 'connection2 should have ended');
35+
assert(connection3Ended, 'connection3 should have ended');
36+
37+
pool.end();
38+
}, 2000);
39+
});
40+
});
41+
});

0 commit comments

Comments
 (0)