不要怂,就是干,撸起袖子干!

Commit 7fdc2dcb by Tony Brix Committed by GitHub

fix(mssql): tedious connect deprecation (#12275)

1 parent 8a3827d0
...@@ -61,6 +61,9 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -61,6 +61,9 @@ class ConnectionManager extends AbstractConnectionManager {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const connection = new this.lib.Connection(connectionConfig); const connection = new this.lib.Connection(connectionConfig);
if (connection.state === connection.STATE.INITIALIZED) {
connection.connect();
}
connection.lib = this.lib; connection.lib = this.lib;
const resourceLock = new ResourceLock(connection); const resourceLock = new ResourceLock(connection);
......
...@@ -39,6 +39,8 @@ if (dialect === 'mssql') { ...@@ -39,6 +39,8 @@ if (dialect === 'mssql') {
it('connectionManager._connect() does not delete `domain` from config.dialectOptions', function() { it('connectionManager._connect() does not delete `domain` from config.dialectOptions', function() {
this.connectionStub.returns({ this.connectionStub.returns({
STATE: {},
state: '',
once(event, cb) { once(event, cb) {
if (event === 'connect') { if (event === 'connect') {
setTimeout(() => { setTimeout(() => {
...@@ -58,6 +60,8 @@ if (dialect === 'mssql') { ...@@ -58,6 +60,8 @@ if (dialect === 'mssql') {
it('connectionManager._connect() should reject if end was called and connect was not', function() { it('connectionManager._connect() should reject if end was called and connect was not', function() {
this.connectionStub.returns({ this.connectionStub.returns({
STATE: {},
state: '',
once(event, cb) { once(event, cb) {
if (event === 'end') { if (event === 'end') {
setTimeout(() => { setTimeout(() => {
...@@ -75,5 +79,29 @@ if (dialect === 'mssql') { ...@@ -75,5 +79,29 @@ if (dialect === 'mssql') {
expect(err.parent.message).to.equal('Connection was closed by remote server'); 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);
});
});
}); });
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!