Skip to content

Commit 3aaef47

Browse files
Erin SpicelandBenjamin Coe
authored andcommitted
Fix bug in mocha tests Redis shutdown which expected exit code to eq 0.
Move a miscategorized select test into the correct describe.
1 parent 5da0833 commit 3aaef47

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

test/lib/redis-process.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ module.exports = {
2323
stop: function (done) {
2424
rp.once("exit", function (code) {
2525
var error = null;
26-
if (code !== 0) error = Error('failed to shutdown redis');
26+
if (code !== null && code !== 0) {
27+
error = Error('Redis shutdown failed with code ' + code);
28+
}
2729
return done(error);
2830
});
2931
rp.kill("SIGINT");

test/mocha/select.spec.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ describe("The 'select' method", function () {
99

1010
var rp;
1111
before(function (done) {
12-
RedisProcess.start(function (err, _rp) {
13-
rp = _rp;
14-
return done(err);
15-
});
12+
RedisProcess.start(function (err, _rp) {
13+
rp = _rp;
14+
return done(err);
15+
});
1616
})
1717

1818
function removeMochaListener () {
19-
var mochaListener = process.listeners('uncaughtException').pop();
20-
process.removeListener('uncaughtException', mochaListener);
21-
return mochaListener;
19+
var mochaListener = process.listeners('uncaughtException').pop();
20+
process.removeListener('uncaughtException', mochaListener);
21+
return mochaListener;
2222
}
2323

2424
function allTests(parser, ip) {
@@ -32,10 +32,10 @@ describe("The 'select' method", function () {
3232
client = redis.createClient.apply(redis.createClient, args);
3333
client.once("error", done);
3434
client.once("connect", function () {
35-
client.quit();
35+
client.quit();
3636
});
3737
client.on('end', function () {
38-
return done();
38+
return done();
3939
});
4040
});
4141

@@ -70,15 +70,14 @@ describe("The 'select' method", function () {
7070
});
7171
});
7272

73-
describe("and no callback is specified", function () {
73+
describe("and a callback is specified", function () {
7474
describe("with a valid db index", function () {
7575
it("selects the appropriate database", function (done) {
7676
assert.strictEqual(client.selected_db, null, "default db should be null");
77-
client.select(1);
78-
setTimeout(function () {
77+
client.select(1, function () {
7978
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
8079
return done();
81-
}, 100);
80+
});
8281
});
8382
});
8483

@@ -90,15 +89,30 @@ describe("The 'select' method", function () {
9089
return done();
9190
});
9291
});
92+
});
93+
});
94+
95+
describe("and no callback is specified", function () {
96+
describe("with a valid db index", function () {
97+
it("selects the appropriate database", function (done) {
98+
assert.strictEqual(client.selected_db, null, "default db should be null");
99+
client.select(1);
100+
setTimeout(function () {
101+
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
102+
return done();
103+
}, 100);
104+
});
105+
});
93106

107+
describe("with an invalid db index", function () {
94108
it("throws an error when callback not provided", function (done) {
95109
var mochaListener = removeMochaListener();
96110
assert.strictEqual(client.selected_db, null, "default db should be null");
97111

98112
process.once('uncaughtException', function (err) {
99-
process.on('uncaughtException', mochaListener);
100-
assert.equal(err.message, 'ERR invalid DB index');
101-
return done();
113+
process.on('uncaughtException', mochaListener);
114+
assert.equal(err.message, 'ERR invalid DB index');
115+
return done();
102116
});
103117

104118
client.select(9999);

test/test.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -938,19 +938,6 @@ tests.socket_nodelay = function () {
938938
c3.on("ready", ready_check);
939939
};
940940

941-
tests.select_error_emits_if_no_callback = function () {
942-
var prev = client.listeners("error")[0];
943-
client.removeListener("error", prev);
944-
var name = "select_error_emits_if_no_callback";
945-
var handler = with_timeout(name, function (err) {
946-
require_error(name)(err);
947-
client.removeListener('error', handler);
948-
client.on("error", prev);
949-
next(name);
950-
}, 500);
951-
client.on('error', handler);
952-
client.select(9999);
953-
};
954941

955942
tests.idle = function () {
956943
var name = "idle";

0 commit comments

Comments
 (0)