1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Fix bug in mocha tests Redis shutdown which expected exit code to eq 0.

Move a miscategorized select test into the correct describe.
This commit is contained in:
Erin Spiceland
2015-07-14 09:45:48 -05:00
committed by Benjamin Coe
parent 5da083322d
commit 3aaef47756
3 changed files with 37 additions and 34 deletions

View File

@@ -23,7 +23,9 @@ module.exports = {
stop: function (done) { stop: function (done) {
rp.once("exit", function (code) { rp.once("exit", function (code) {
var error = null; 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); return done(error);
}); });
rp.kill("SIGINT"); rp.kill("SIGINT");

View File

@@ -9,16 +9,16 @@ describe("The 'select' method", function () {
var rp; var rp;
before(function (done) { before(function (done) {
RedisProcess.start(function (err, _rp) { RedisProcess.start(function (err, _rp) {
rp = _rp; rp = _rp;
return done(err); return done(err);
}); });
}) })
function removeMochaListener () { function removeMochaListener () {
var mochaListener = process.listeners('uncaughtException').pop(); var mochaListener = process.listeners('uncaughtException').pop();
process.removeListener('uncaughtException', mochaListener); process.removeListener('uncaughtException', mochaListener);
return mochaListener; return mochaListener;
} }
function allTests(parser, ip) { function allTests(parser, ip) {
@@ -32,10 +32,10 @@ describe("The 'select' method", function () {
client = redis.createClient.apply(redis.createClient, args); client = redis.createClient.apply(redis.createClient, args);
client.once("error", done); client.once("error", done);
client.once("connect", function () { client.once("connect", function () {
client.quit(); client.quit();
}); });
client.on('end', function () { 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("and no callback is specified", function () {
describe("with a valid db index", function () { describe("with a valid db index", function () {
it("selects the appropriate database", function (done) { it("selects the appropriate database", function (done) {
@@ -83,22 +105,14 @@ describe("The 'select' method", function () {
}); });
describe("with an invalid db index", 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) { it("throws an error when callback not provided", function (done) {
var mochaListener = removeMochaListener(); var mochaListener = removeMochaListener();
assert.strictEqual(client.selected_db, null, "default db should be null"); assert.strictEqual(client.selected_db, null, "default db should be null");
process.once('uncaughtException', function (err) { process.once('uncaughtException', function (err) {
process.on('uncaughtException', mochaListener); process.on('uncaughtException', mochaListener);
assert.equal(err.message, 'ERR invalid DB index'); assert.equal(err.message, 'ERR invalid DB index');
return done(); return done();
}); });
client.select(9999); client.select(9999);

View File

@@ -938,19 +938,6 @@ tests.socket_nodelay = function () {
c3.on("ready", ready_check); 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 () { tests.idle = function () {
var name = "idle"; var name = "idle";