Skip to content

Commit f1ce72e

Browse files
committed
tests: improve timeout tests
1 parent bfdea65 commit f1ce72e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

test/unit/connection/test-query-timeout.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,27 @@ var common = require('../../common');
33
var connection = common.createConnection({port: common.fakeServerPort});
44
var server = common.createFakeServer();
55

6-
var connClosed = false;
6+
var timer = setTimeout(function () {
7+
throw new Error('test timeout');
8+
}, 2000);
79

810
server.listen(common.fakeServerPort, function(err) {
911
if (err) throw err;
1012

11-
connection.query({sql: 'SELECT 1', timeout: 20}, function (err, rows) {
13+
connection.query({sql: 'SELECT 1', timeout: 200}, function (err, rows) {
1214
assert.ok(err);
1315
assert.equal(err.code, 'PROTOCOL_SEQUENCE_TIMEOUT');
1416
assert.equal(err.fatal, true);
1517
assert.equal(err.message, 'Query inactivity timeout');
16-
assert.equal(err.timeout, 20);
17-
18-
setTimeout(function() {
19-
assert.ok(connClosed);
20-
server.destroy();
21-
}, 10);
18+
assert.equal(err.timeout, 200);
2219
});
2320
});
2421

2522
server.on('connection', function(conn) {
2623
conn.handshake();
2724
conn._socket.on('close', function() {
28-
connClosed = true;
25+
clearTimeout(timer);
26+
server.destroy();
2927
});
3028
conn.on('query', function(packet) {
3129
// Do nothing; timeout

test/unit/pool/test-acquire-timeout-existing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var assert = require('assert');
22
var common = require('../../common');
33
var pool = common.createPool({
4-
acquireTimeout : 100,
4+
acquireTimeout : 200,
55
connectionLimit : 1,
66
port : common.fakeServerPort
77
});

0 commit comments

Comments
 (0)