Skip to content

Commit bdfbe5b

Browse files
fix test case of release idle connection
1 parent d4427a2 commit bdfbe5b

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const pool = mysql.createPool({
131131
waitForConnections: true,
132132
connectionLimit: 10,
133133
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
134+
idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
134135
queueLimit: 0
135136
});
136137
```

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ export interface ConnectionOptions extends mysql.ConnectionOptions {
174174
stream?: any;
175175
uri?: string;
176176
connectionLimit?: number;
177+
maxIdle?: number;
178+
idleTimeout?: number;
177179
Promise?: any;
178180
queueLimit?: number;
179181
waitForConnections?: boolean;

test/integration/test-pool-release-idle-connection.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
'use strict';
22

3-
const mysql = require('../../index');
3+
const createPool = require('../common.js').createPool;
4+
const config = require('../common.js').config;
45
const assert = require('assert');
56

6-
const poolConfig = {
7-
host: 'localhost',
8-
port: 3306,
9-
user: 'root',
10-
password: 'test',
11-
connectionLimit: 10,
12-
maxIdle: 1,
13-
idleTimeout: 5000
14-
};
7+
const options = Object.assign({
8+
connectionLimit: 5, // 5 connections
9+
maxIdle: 1, // 1 idle connection
10+
idleTimeout: 5000, // 5 seconds
11+
}, config);
12+
const pool = new createPool(options);
1513

16-
const pool = new mysql.createPool(poolConfig);
1714
pool.getConnection((err1, connection1) => {
1815
assert.ifError(err1);
1916
assert.ok(connection1);

typings/mysql/lib/Pool.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ declare namespace Pool {
2626
*/
2727
connectionLimit?: number;
2828

29+
/**
30+
* The minimum number of idle connections. (Default: 10)
31+
*/
32+
maxIdle?: number;
33+
34+
/**
35+
* The idle connections timeout, in milliseconds. (Default: 60000)
36+
*/
37+
idleTimeout?: number;
38+
2939
/**
3040
* The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
3141
* is no limit to the number of queued connection requests. (Default: 0)

0 commit comments

Comments
 (0)