Skip to content

Commit 1b542f8

Browse files
committed
test(timeout): add connectTimeout test
1 parent 309703a commit 1b542f8

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

test/common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ exports.createConnection = function(args) {
121121
dateStrings: args && args.dateStrings,
122122
authSwitchHandler: args && args.authSwitchHandler,
123123
typeCast: args && args.typeCast,
124-
namedPlaceholders: args && args.namedPlaceholders
124+
namedPlaceholders: args && args.namedPlaceholders,
125+
connectTimeout: args && args.connectTimeout,
125126
};
126127

127128
const conn = driver.createConnection(params);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../../common');
4+
const connection = common.createConnection({
5+
host: '10.255.255.1',
6+
debug: false,
7+
connectTimeout: 100,
8+
});
9+
10+
const assert = require('assert');
11+
12+
connection.query('SELECT sleep(3) as a', (err, res) => {
13+
assert.equal(res, null);
14+
assert.ok(err);
15+
assert.equal(err.code, 'ETIMEDOUT');
16+
assert.equal(err.message, 'connect ETIMEDOUT');
17+
});
18+
19+
connection.query({ sql: 'SELECT sleep(3) as a' , timeout: 50}, (err, res) => {
20+
assert.equal(res, null);
21+
assert.ok(err);
22+
assert.equal(err.code, 'ETIMEDOUT');
23+
assert.equal(err.message, 'connect ETIMEDOUT');
24+
});
25+
26+
27+

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ connection.execute('SELECT sleep(1) as a', (err, res) => {
3434
assert.deepEqual(res, [{ a: 0 }]);
3535
connection.end();
3636
});
37+
38+
const connectionTimeout = common.createConnection({
39+
host: '10.255.255.1',
40+
debug: false,
41+
connectTimeout: 100,
42+
});
43+
44+
// return connect timeout error first
45+
connectionTimeout.query({ sql: 'SELECT sleep(3) as a', timeout: 50 }, (err, res) => {
46+
assert.equal(res, null);
47+
assert.ok(err);
48+
assert.equal(err.code, 'ETIMEDOUT');
49+
assert.equal(err.message, 'connect ETIMEDOUT');
50+
});

0 commit comments

Comments
 (0)