From 3aaef4775608a9213fdc83df612511bbbe345d59 Mon Sep 17 00:00:00 2001 From: Erin Spiceland Date: Tue, 14 Jul 2015 09:45:48 -0500 Subject: [PATCH] Fix bug in mocha tests Redis shutdown which expected exit code to eq 0. Move a miscategorized select test into the correct describe. --- test/lib/redis-process.js | 4 ++- test/mocha/select.spec.js | 54 ++++++++++++++++++++++++--------------- test/test.js | 13 ---------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/test/lib/redis-process.js b/test/lib/redis-process.js index b1141f7f10..24d7f04f60 100644 --- a/test/lib/redis-process.js +++ b/test/lib/redis-process.js @@ -23,7 +23,9 @@ module.exports = { stop: function (done) { rp.once("exit", function (code) { var error = null; - if (code !== 0) error = Error('failed to shutdown redis'); + if (code !== null && code !== 0) { + error = Error('Redis shutdown failed with code ' + code); + } return done(error); }); rp.kill("SIGINT"); diff --git a/test/mocha/select.spec.js b/test/mocha/select.spec.js index 18fb34c642..bde75857f6 100644 --- a/test/mocha/select.spec.js +++ b/test/mocha/select.spec.js @@ -9,16 +9,16 @@ describe("The 'select' method", function () { var rp; before(function (done) { - RedisProcess.start(function (err, _rp) { - rp = _rp; - return done(err); - }); + RedisProcess.start(function (err, _rp) { + rp = _rp; + return done(err); + }); }) function removeMochaListener () { - var mochaListener = process.listeners('uncaughtException').pop(); - process.removeListener('uncaughtException', mochaListener); - return mochaListener; + var mochaListener = process.listeners('uncaughtException').pop(); + process.removeListener('uncaughtException', mochaListener); + return mochaListener; } function allTests(parser, ip) { @@ -32,10 +32,10 @@ describe("The 'select' method", function () { client = redis.createClient.apply(redis.createClient, args); client.once("error", done); client.once("connect", function () { - client.quit(); + client.quit(); }); client.on('end', function () { - return done(); + return done(); }); }); @@ -70,6 +70,28 @@ describe("The 'select' method", function () { }); }); + describe("and a callback is specified", function () { + describe("with a valid db index", function () { + it("selects the appropriate database", function (done) { + assert.strictEqual(client.selected_db, null, "default db should be null"); + client.select(1, function () { + assert.equal(client.selected_db, 1, "we should have selected the new valid DB"); + return done(); + }); + }); + }); + + describe("with an invalid db index", function () { + it("emits an error", function (done) { + assert.strictEqual(client.selected_db, null, "default db should be null"); + client.select(9999, function (err) { + assert.equal(err.message, 'ERR invalid DB index') + return done(); + }); + }); + }); + }); + describe("and no callback is specified", function () { describe("with a valid db index", function () { it("selects the appropriate database", function (done) { @@ -83,22 +105,14 @@ describe("The 'select' method", function () { }); describe("with an invalid db index", function () { - it("emits an error", function (done) { - assert.strictEqual(client.selected_db, null, "default db should be null"); - client.select(9999, function (err) { - assert.equal(err.message, 'ERR invalid DB index') - return done(); - }); - }); - it("throws an error when callback not provided", function (done) { var mochaListener = removeMochaListener(); assert.strictEqual(client.selected_db, null, "default db should be null"); process.once('uncaughtException', function (err) { - process.on('uncaughtException', mochaListener); - assert.equal(err.message, 'ERR invalid DB index'); - return done(); + process.on('uncaughtException', mochaListener); + assert.equal(err.message, 'ERR invalid DB index'); + return done(); }); client.select(9999); diff --git a/test/test.js b/test/test.js index 9142a144ca..6021fcdfa9 100644 --- a/test/test.js +++ b/test/test.js @@ -938,19 +938,6 @@ tests.socket_nodelay = function () { c3.on("ready", ready_check); }; -tests.select_error_emits_if_no_callback = function () { - var prev = client.listeners("error")[0]; - client.removeListener("error", prev); - var name = "select_error_emits_if_no_callback"; - var handler = with_timeout(name, function (err) { - require_error(name)(err); - client.removeListener('error', handler); - client.on("error", prev); - next(name); - }, 500); - client.on('error', handler); - client.select(9999); -}; tests.idle = function () { var name = "idle";