You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Do not emit the broken mode twice if exec is called
Add more tests
This commit is contained in:
@@ -19,9 +19,7 @@ describe("on lost connection", function () {
|
||||
var calls = 0;
|
||||
|
||||
client.once('ready', function() {
|
||||
// Pretend that redis can't reconnect
|
||||
client.on_connect = client.on_error;
|
||||
client.stream.destroy();
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
@@ -40,16 +38,14 @@ describe("on lost connection", function () {
|
||||
|
||||
it("emit an error after max retry timeout and do not try to reconnect afterwards", function (done) {
|
||||
var connect_timeout = 1000; // in ms
|
||||
client = redis.createClient({
|
||||
var client = redis.createClient({
|
||||
parser: parser,
|
||||
connect_timeout: connect_timeout
|
||||
});
|
||||
var time = 0;
|
||||
|
||||
client.once('ready', function() {
|
||||
// Pretend that redis can't reconnect
|
||||
client.on_connect = client.on_error;
|
||||
client.stream.destroy();
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
@@ -66,6 +62,23 @@ describe("on lost connection", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("end connection while retry is still ongoing", function (done) {
|
||||
var connect_timeout = 1000; // in ms
|
||||
var client = redis.createClient({
|
||||
parser: parser,
|
||||
connect_timeout: connect_timeout
|
||||
});
|
||||
|
||||
client.once('ready', function() {
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
client.end();
|
||||
setTimeout(done, 100);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -145,5 +145,15 @@ module.exports = {
|
||||
func();
|
||||
}
|
||||
};
|
||||
},
|
||||
killConnection: function (client) {
|
||||
// Change the connection option to a non existing one and destroy the stream
|
||||
client.connectionOption = {
|
||||
port: 6370,
|
||||
host: '127.0.0.2',
|
||||
family: 4
|
||||
};
|
||||
client.address = '127.0.0.2:6370';
|
||||
client.stream.destroy();
|
||||
}
|
||||
};
|
||||
|
@@ -729,9 +729,11 @@ describe("The node_redis client", function () {
|
||||
client.on('reconnecting', function(params) {
|
||||
i++;
|
||||
assert.equal(params.attempt, i);
|
||||
assert.strictEqual(client.offline_queue.length, 1);
|
||||
assert.strictEqual(client.offline_queue.length, 2);
|
||||
});
|
||||
|
||||
// Should work with either a callback or without
|
||||
client.set('baz', 13);
|
||||
client.set('foo', 'bar', function(err, result) {
|
||||
assert(i, 3);
|
||||
assert('Redis connection gone from error event', err.message);
|
||||
@@ -764,6 +766,40 @@ describe("The node_redis client", function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("flushes the command queue connection if in broken connection mode", function (done) {
|
||||
var client = redis.createClient({
|
||||
parser: parser,
|
||||
max_attempts: 2,
|
||||
enable_offline_queue: false
|
||||
});
|
||||
|
||||
client.once('ready', function() {
|
||||
var multi = client.multi();
|
||||
multi.config("bar");
|
||||
var cb = function(err, reply) {
|
||||
assert.equal(err.code, 'CONNECTION_BROKEN');
|
||||
};
|
||||
for (var i = 0; i < 10; i += 2) {
|
||||
multi.set("foo" + i, "bar" + i);
|
||||
multi.set("foo" + (i + 1), "bar" + (i + 1), cb);
|
||||
}
|
||||
multi.exec();
|
||||
assert.equal(client.command_queue.length, 13);
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
assert.equal(client.command_queue.length, 13);
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
if (/Redis connection in broken state:/.test(err.message)) {
|
||||
assert.equal(client.command_queue.length, 0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user