forked from mysqljs/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-idle-connection-timeout.js
38 lines (34 loc) · 1.03 KB
/
test-idle-connection-timeout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var assert = require('assert');
var common = require('../../common');
var pool = common.createPool({
port : common.fakeServerPort,
idleConnectionTimeout : 100
});
var server = common.createFakeServer();
server.listen(common.fakeServerPort, function(err){
assert.ifError(err);
pool.once('release', function(connection) {
assert.ok(connection);
setTimeout(function() {
assert.equal(connection.state, 'disconnected');
pool.end(function (err) {
assert.ifError(err);
server.destroy();
});
}, 200);
});
pool.getConnection(function (err, firstConnection) {
assert.ifError(err);
assert.ok(firstConnection);
setTimeout(function() {
pool.getConnection(function (err, connection) {
assert.ifError(err);
assert.equal(connection.state, 'authenticated');
assert.equal(connection._idleTimeout, null);
assert.equal(firstConnection, connection);
connection.release();
});
}, 75);
firstConnection.release();
});
});