Skip to content

Commit cd9e903

Browse files
Move this test to be a unit test.
1 parent c349ba1 commit cd9e903

2 files changed

Lines changed: 33 additions & 42 deletions

File tree

test/integration/connection-test.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -625,48 +625,7 @@ describe('Encrypt Test', function() {
625625
connection.execSql(request);
626626
});
627627
}
628-
it ('Timeout handled correctly with strict encryption enabled (TDS 8.0)', function(done) {
629-
const config = getConfig();
630-
supportsTds8(config, async (err, supportsTds8) => {
631-
if (err) {
632-
return done(err);
633-
}
634-
635-
if (!supportsTds8) {
636-
return this.skip();
637-
}
638-
639-
/**
640-
* @type {net.Server}
641-
*/
642-
643-
const targetServer = net.createServer();
644-
targetServer.on('connection', () => {});
645-
targetServer.listen(0, '127.0.0.1', () => {
646-
assert(targetServer.address());
647-
const addressInfo = /** @type {net.AddressInfo} */(targetServer.address());
648-
const connection = new Connection({
649-
server: addressInfo?.address,
650-
options: {
651-
port: addressInfo?.port,
652-
encrypt: 'strict',
653-
connectTimeout: 3000
654-
}
655-
});
656628

657-
connection.connect((err) => {
658-
assert.instanceOf(err, ConnectionError);
659-
const message = `Failed to connect to ${addressInfo?.address}:${addressInfo?.port} in 3000ms`;
660-
assert.equal(/** @type {Error} */(err).message, message);
661-
connection.close();
662-
});
663-
connection.on('end', function() {
664-
done();
665-
});
666-
});
667-
setTimeout(() => targetServer.close(done), 4000);
668-
});
669-
});
670629
describe('with strict encryption enabled (TDS 8.0)', function() {
671630
/**
672631
* @type {Connection}

test/unit/connection-test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as net from 'net';
2-
import { Connection } from '../../src/tedious';
2+
import { Connection, ConnectionError } from '../../src/tedious';
33
import { assert } from 'chai';
44

55
describe('Using `strict` encryption', function() {
@@ -42,4 +42,36 @@ describe('Using `strict` encryption', function() {
4242
done();
4343
});
4444
});
45+
46+
it('handles connection timeout when performing tls handshake', function(done) {
47+
server.on('connection', (connection) => {
48+
setTimeout(() => {
49+
connection.destroy();
50+
}, 4000);
51+
});
52+
53+
const addressInfo = server.address() as net.AddressInfo;
54+
55+
const connection = new Connection({
56+
server: addressInfo?.address,
57+
options: {
58+
port: addressInfo?.port,
59+
encrypt: 'strict',
60+
connectTimeout: 3000
61+
}
62+
});
63+
64+
connection.connect((err) => {
65+
assert.instanceOf(err, ConnectionError);
66+
67+
const message = `Failed to connect to ${addressInfo?.address}:${addressInfo?.port} in 3000ms`;
68+
assert.equal(err!.message, message);
69+
70+
connection.close();
71+
});
72+
73+
connection.on('end', () => {
74+
done();
75+
});
76+
});
4577
});

0 commit comments

Comments
 (0)