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 test and fix keeping the offline queue
Use a new delay after reconnecting
This commit is contained in:
@@ -11,7 +11,7 @@ describe("on lost connection", function () {
|
||||
describe("using " + parser + " and " + ip, function () {
|
||||
|
||||
it("emit an error after max retry attempts and do not try to reconnect afterwards", function (done) {
|
||||
var max_attempts = 3;
|
||||
var max_attempts = 4;
|
||||
var client = redis.createClient({
|
||||
parser: parser,
|
||||
max_attempts: max_attempts
|
||||
@@ -31,7 +31,7 @@ describe("on lost connection", function () {
|
||||
client.on('error', function(err) {
|
||||
if (/Redis connection in broken state: maximum connection attempts.*?exceeded./.test(err.message)) {
|
||||
setTimeout(function () {
|
||||
assert.strictEqual(calls, max_attempts);
|
||||
assert.strictEqual(calls, max_attempts - 1);
|
||||
done();
|
||||
}, 1500);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ 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
|
||||
var client = redis.createClient({
|
||||
client = redis.createClient({
|
||||
parser: parser,
|
||||
connect_timeout: connect_timeout
|
||||
});
|
||||
|
@@ -688,7 +688,7 @@ describe("The node_redis client", function () {
|
||||
describe('true', function () {
|
||||
it("does not return an error and enqueues operation", function (done) {
|
||||
var client = redis.createClient(9999, null, {
|
||||
max_attempts: 0,
|
||||
max_attempts: 1,
|
||||
parser: parser
|
||||
});
|
||||
|
||||
@@ -710,6 +710,34 @@ describe("The node_redis client", function () {
|
||||
}, 25);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
it("enqueues operation and keep the queue while trying to reconnect", function (done) {
|
||||
var client = redis.createClient(9999, null, {
|
||||
max_attempts: 4,
|
||||
parser: parser
|
||||
});
|
||||
var i = 0;
|
||||
|
||||
client.on('error', function(err) {
|
||||
if (err.message === 'Redis connection in broken state: maximum connection attempts exceeded.') {
|
||||
assert(i, 3);
|
||||
assert.strictEqual(client.offline_queue.length, 0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
client.on('reconnecting', function(params) {
|
||||
i++;
|
||||
assert.equal(params.attempt, i);
|
||||
assert.strictEqual(client.offline_queue.length, 1);
|
||||
});
|
||||
|
||||
client.set('foo', 'bar', function(err, result) {
|
||||
assert(i, 3);
|
||||
assert('Redis connection gone from error event', err.message);
|
||||
assert.strictEqual(client.offline_queue.length, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('false', function () {
|
||||
|
Reference in New Issue
Block a user