You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Add warnings and handle protocol errors gracefuly
This commit is contained in:
@@ -364,11 +364,20 @@ describe("connection tests", function () {
|
||||
});
|
||||
|
||||
if (ip === 'IPv4') {
|
||||
it('allows connecting with the redis url and the default port', function (done) {
|
||||
it('allows connecting with the redis url to the default host and port, select db 3 and warn about duplicate db option', function (done) {
|
||||
client = redis.createClient('redis:///3?db=3');
|
||||
assert.strictEqual(client.selected_db, '3');
|
||||
client.on("ready", done);
|
||||
});
|
||||
|
||||
it('allows connecting with the redis url and the default port and auth provided even though it is not required', function (done) {
|
||||
client = redis.createClient('redis://:porkchopsandwiches@' + config.HOST[ip] + '/');
|
||||
client.on("ready", function () {
|
||||
return done();
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(msg, 'Warning: Redis server does not require a password, but a password was supplied.');
|
||||
end();
|
||||
});
|
||||
client.on("ready", end);
|
||||
});
|
||||
|
||||
it('allows connecting with the redis url as first parameter and the options as second parameter', function (done) {
|
||||
|
@@ -171,7 +171,10 @@ module.exports = {
|
||||
},
|
||||
callFuncAfter: function (func, max) {
|
||||
var i = 0;
|
||||
return function () {
|
||||
return function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
i++;
|
||||
if (i === max) {
|
||||
func();
|
||||
|
@@ -550,6 +550,28 @@ describe("The node_redis client", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('protocol error', function () {
|
||||
|
||||
it("should gracefully recover and only fail on the already send commands", function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.on('error', function(err) {
|
||||
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte');
|
||||
// After the hard failure work properly again. The set should have been processed properly too
|
||||
client.get('foo', function (err, res) {
|
||||
assert.strictEqual(res, 'bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
client.once('ready', function () {
|
||||
client.set('foo', 'bar', function (err, res) {
|
||||
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte');
|
||||
});
|
||||
// Fail the set answer. Has no corresponding command obj and will therefor land in the error handler and set
|
||||
client.reply_parser.execute(new Buffer('a*1\r*1\r$1`zasd\r\na'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('enable_offline_queue', function () {
|
||||
describe('true', function () {
|
||||
it("should emit drain if offline queue is flushed and nothing to buffer", function (done) {
|
||||
|
@@ -18,17 +18,24 @@ describe("return_buffers", function () {
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
var i = 1;
|
||||
if (args[2].detect_buffers) {
|
||||
// Test if detect_buffer option was deactivated
|
||||
assert.strictEqual(client.options.detect_buffers, false);
|
||||
args[2].detect_buffers = false;
|
||||
i++;
|
||||
}
|
||||
var end = helper.callFuncAfter(done, i);
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(msg, 'WARNING: You activated return_buffers and detect_buffers at the same time. The return value is always going to be a buffer.');
|
||||
end();
|
||||
});
|
||||
client.once("error", done);
|
||||
client.once("connect", function () {
|
||||
client.flushdb(function (err) {
|
||||
client.hmset("hash key 2", "key 1", "val 1", "key 2", "val 2");
|
||||
client.set("string key 1", "string value");
|
||||
return done(err);
|
||||
end(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user