Skip to content

Commit

Permalink
fix(mssql): tedious v9 requires connect call (#12182)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 28, 2020
1 parent f1e451e commit 5dcc0d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/dialects/mssql/connection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class ConnectionManager extends AbstractConnectionManager {
try {
return await new Promise((resolve, reject) => {
const connection = new this.lib.Connection(connectionConfig);
if (connection.state === connection.STATE.INITIALIZED) {
connection.connect();
}
connection.queue = new AsyncQueue();
connection.lib = this.lib;

Expand Down
28 changes: 28 additions & 0 deletions test/unit/dialects/mssql/connection-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ if (dialect === 'mssql') {

it('connectionManager._connect() does not delete `domain` from config.dialectOptions', function() {
this.connectionStub.returns({
STATE: {},
state: '',
once(event, cb) {
if (event === 'connect') {
setTimeout(() => {
Expand All @@ -58,6 +60,8 @@ if (dialect === 'mssql') {

it('connectionManager._connect() should reject if end was called and connect was not', function() {
this.connectionStub.returns({
STATE: {},
state: '',
once(event, cb) {
if (event === 'end') {
setTimeout(() => {
Expand All @@ -75,5 +79,29 @@ if (dialect === 'mssql') {
expect(err.parent.message).to.equal('Connection was closed by remote server');
});
});

it('connectionManager._connect() should call connect if state is initialized', function() {
const connectStub = sinon.stub();
const INITIALIZED = { name: 'INITIALIZED' };
this.connectionStub.returns({
STATE: { INITIALIZED },
state: INITIALIZED,
connect: connectStub,
once(event, cb) {
if (event === 'connect') {
setTimeout(() => {
cb();
}, 500);
}
},
removeListener: () => {},
on: () => {}
});

return this.instance.dialect.connectionManager._connect(this.config)
.then(() => {
expect(connectStub.called).to.equal(true);
});
});
});
}

0 comments on commit 5dcc0d5

Please sign in to comment.