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

Add tests and emit UNCERTAIN_STATE errors

This commit is contained in:
Ruben Bridgewater
2015-10-28 00:58:11 +01:00
parent 0ec2c43603
commit d39f6961e6
3 changed files with 33 additions and 3 deletions

View File

@@ -530,6 +530,8 @@ RedisClient.prototype.connection_gone = function (why) {
// error.message = 'Command aborted in uncertain state and queued for next connection.'; // error.message = 'Command aborted in uncertain state and queued for next connection.';
// } // }
this.flush_and_error(error, ['command_queue']); this.flush_and_error(error, ['command_queue']);
error.message = 'Redis connection lost and commands aborted in uncertain state. They might have been processed.';
this.emit('error', error);
} }
if (this.retry_max_delay !== null && this.retry_delay > this.retry_max_delay) { if (this.retry_max_delay !== null && this.retry_delay > this.retry_max_delay) {
@@ -1109,11 +1111,12 @@ Multi.prototype.execute_callback = function (err, replies) {
if (err) { if (err) {
// The errors would be circular // The errors would be circular
err.errors = err.code !== 'CONNECTION_BROKEN' ? this.errors : []; var connection_error = ['CONNECTION_BROKEN', 'UNCERTAIN_STATE'].indexOf(err.code) !== -1;
err.errors = connection_error ? [] : this.errors;
if (this.callback) { if (this.callback) {
this.callback(err); this.callback(err);
} else if (err.code !== 'CONNECTION_BROKEN') { // Exclude connection errors so that those errors won't be emitted twice
// Exclude CONNECTION_BROKEN so that error won't be emitted twice } else if (!connection_error) {
this._client.emit('error', err); this._client.emit('error', err);
} }
return; return;

View File

@@ -553,6 +553,19 @@ describe("The 'multi' method", function () {
}); });
}); });
it("emits error once if reconnecting after multi has been executed but not yet returned without callback", function (done) {
helper.serverVersionAtLeast.call(this, client, [2, 6, 5]);
client.on('error', function(err) {
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
done();
});
client.multi().set("foo", 'bar').get('foo').exec();
// Abort connection before the value returned
client.stream.destroy();
});
}); });
}); });
}); });

View File

@@ -107,6 +107,20 @@ describe("connection tests", function () {
}); });
}); });
it("emits error once if reconnecting after command has been executed but not yet returned without callback", function (done) {
client = redis.createClient.apply(redis.createClient, args);
client.on('error', function(err) {
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
done();
});
client.on('ready', function() {
client.set("foo", 'bar');
// Abort connection before the value returned
client.stream.destroy();
});
});
}); });
describe("when not connected", function () { describe("when not connected", function () {