diff --git a/src/database/mongo.js b/src/database/mongo.js index 7336570e16..21c5a97638 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -201,11 +201,18 @@ mongoModule.checkCompatibilityVersion = function (version, callback) { }; mongoModule.info = function (db, callback) { - if (!db) { - return callback(); - } async.waterfall([ function (next) { + if (db) { + return setImmediate(next, null, db); + } + mongoModule.connect(nconf.get('mongo'), function (err, client) { + next(err, client ? client.db() : undefined); + }); + }, + function (db, next) { + mongoModule.client = mongoModule.client || db; + async.parallel({ serverStatus: function (next) { db.command({ serverStatus: 1 }, next); diff --git a/src/database/postgres.js b/src/database/postgres.js index 5284e76b68..d7358875ec 100644 --- a/src/database/postgres.js +++ b/src/database/postgres.js @@ -450,19 +450,26 @@ postgresModule.checkCompatibilityVersion = function (version, callback) { }; postgresModule.info = function (db, callback) { - if (!db) { - return callback(); - } - - db.query(` -SELECT true "postgres", - current_setting('server_version') "version", - EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, function (err, res) { - if (err) { - return callback(err); - } - callback(null, res.rows[0]); - }); + async.waterfall([ + function (next) { + if (db) { + setImmediate(next, null, db); + } else { + postgresModule.connect(nconf.get('postgres'), next); + } + }, + function (db, next) { + postgresModule.pool = postgresModule.pool || db; + + db.query(` + SELECT true "postgres", + current_setting('server_version') "version", + EXTRACT(EPOCH FROM NOW() - pg_postmaster_start_time()) * 1000 "uptime"`, next); + }, + function (res, next) { + next(null, res.rows[0]); + }, + ], callback); }; postgresModule.close = function (callback) { diff --git a/src/database/redis.js b/src/database/redis.js index 4cbca8104b..2828f84915 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -98,7 +98,7 @@ redisModule.connect = function (options, callback) { cxn.on('ready', function () { if (!callbackCalled) { callbackCalled = true; - callback(); + callback(null, cxn); } }); @@ -163,11 +163,16 @@ redisModule.close = function (callback) { }; redisModule.info = function (cxn, callback) { - if (!cxn) { - return callback(); - } async.waterfall([ function (next) { + if (cxn) { + return setImmediate(next, null, cxn); + } + redisModule.connect(nconf.get('redis'), next); + }, + function (cxn, next) { + redisModule.client = redisModule.client || cxn; + cxn.info(next); }, function (data, next) { diff --git a/test/database.js b/test/database.js index b88e425fd6..e54103fff5 100644 --- a/test/database.js +++ b/test/database.js @@ -22,10 +22,10 @@ describe('Test database', function () { }); }); - it('should not error and return null if client is falsy', function (done) { + it('should not error and return info if client is falsy', function (done) { db.info(null, function (err, info) { assert.ifError(err); - assert.equal(info, null); + assert(info); done(); }); });