Skip to content

Commit

Permalink
Fix multidb connect scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpenev-s committed Nov 21, 2017
1 parent 05d2815 commit 70be9c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/protocol/Connection.js
Expand Up @@ -530,8 +530,14 @@ Connection.prototype.rollback = function rollback(options, cb) {
this.enqueue(request.rollback(options), cb);
};

// The function doesn't use the queue. It's used before the queue starts running
Connection.prototype.fetchDbConnectInfo = function (options, cb) {
this.enqueue(request.dbConnectInfo(options), function(err, reply) {
if (this.readyState == 'closed') {
var err = new Error('Connection unexpectedly closed');
err.code = 'EHDBCLOSE';
return cb(err)
}
this.send(request.dbConnectInfo(options), function(err, reply) {
if (err) {
return cb(err);
}
Expand Down
21 changes: 17 additions & 4 deletions test/lib.Connection.js
Expand Up @@ -406,19 +406,32 @@ describe('Lib', function () {
return connection;
}

it('should fetch DB_CONNECT_INFO with an error', function (done) {
it('should fetch DB_CONNECT_INFO with an error (no state)', function (done) {
var connection = prepareConnection(DATA.NOT_CONNECTED);
connection._socket = undefined;

connection._state = undefined;
connection.fetchDbConnectInfo({}, function (err, info) {
err.code.should.equal('EHDBCLOSE')
done();
});
});

it('fetch DB_CONNECT_INFO with an error (send error)', function (done) {
var connection = createConnection();
connection._socket = {
readyState: 'open'
};
connection.send = function (msg, cb) {
cb(new Error('Request was not successful'));
};

connection.fetchDbConnectInfo({}, function (err) {
err.message.should.equal('Request was not successful');
done();
});
});

it('should fetch DB_CONNECT_INFO (connected)', function (done) {
var connection = prepareConnection(DATA.CONNECTED);
connection._queue.resume();
connection.fetchDbConnectInfo({}, function (err, info) {
info.isConnected.should.equal(true);
(!!info.host).should.be.not.ok;
Expand Down

0 comments on commit 70be9c2

Please sign in to comment.