1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Merge pull request #826 from fintura/multi

Fix multi error handling
This commit is contained in:
Ruben Bridgewater
2015-09-18 00:38:05 +02:00
4 changed files with 80 additions and 22 deletions

View File

@@ -249,15 +249,52 @@ describe("The 'multi' method", function () {
});
});
it('reports multiple exceptions when they occur', function (done) {
it('reports EXECABORT exceptions when they occur (while queueing)', function (done) {
client.multi().config("bar").set("foo").exec(function (err, reply) {
assert.equal(err.code, "EXECABORT");
assert.equal(reply, undefined, "The reply should have been discarded");
assert(err.message.match(/^EXECABORT/), "Error message should begin with EXECABORT");
assert.equal(err.errors.length, 1, "err.errors should have 1 items");
assert.strictEqual(err.errors[0].command_used, 'SET');
assert.strictEqual(err.errors[0].position, 1);
assert(/^ERR/.test(err.errors[0].message), "Actuall error message should begin with ERR");
return done();
});
});
it('reports multiple exceptions when they occur (while EXEC is running)', function (done) {
client.multi().config("bar").debug("foo").exec(function (err, reply) {
assert.strictEqual(reply.length, 2);
assert(/^ERR/.test(reply[0].message), "Error message should begin with ERR");
assert(/^ERR/.test(reply[1].message), "Error message should begin with ERR");
return done();
});
});
it('reports multiple exceptions when they occur (while EXEC is running) and calls cb', function (done) {
var multi = client.multi();
multi.config("bar", helper.isError());
multi.set('foo', 'bar', helper.isString('OK'));
multi.debug("foo").exec(function (err, reply) {
assert.strictEqual(reply.length, 3);
assert(/^ERR/.test(reply[0].message), "Error message should begin with ERR");
assert(/^ERR/.test(reply[2].message), "Error message should begin with ERR");
assert.strictEqual(reply[1], "OK");
client.get('foo', helper.isString('bar', done));
});
});
it("emits an error if no callback has been provided and execabort error occured", function (done) {
helper.serverVersionAtLeast.call(this, client, [2, 6, 5]);
client.multi().set("foo").exec(function (err, reply) {
assert(Array.isArray(err), "err should be an array");
assert.equal(2, err.length, "err should have 2 items");
assert(err[0].message.match(/^ERR/), "First error message should begin with ERR");
assert(err[1].message.match(/^EXECABORT/), "First error message should begin with EXECABORT");
return done();
var multi = client.multi();
multi.config("bar");
multi.set("foo");
multi.exec();
client.on('error', function(err) {
assert.equal(err.code, "EXECABORT");
done();
});
});

View File

@@ -77,6 +77,21 @@ describe("The node_redis client", function () {
});
});
it("connects correctly to localhost and no ready check", function (done) {
client = redis.createClient(undefined, undefined, {
no_ready_check: true
});
client.on("error", done);
client.once("ready", function () {
client.set('foo', 'bar');
client.get('foo', function(err, res) {
assert.strictEqual(res, 'bar');
done(err);
});
});
});
it("throws on strange connection info", function () {
try {
redis.createClient(true);