Skip to content

Commit

Permalink
fix(connection): fail only if redis connection does not recover
Browse files Browse the repository at this point in the history
  • Loading branch information
gmauricio authored and manast committed Sep 8, 2021
1 parent b5d55ec commit 0ca4c6b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ function isRedisReady(client) {
resolve();
} else {
function handleReady() {
client.removeListener('end', handleEnd);
client.removeListener('error', handleError);
resolve();
}

let lastError;
function handleError(err) {
lastError = err;
}

function handleEnd() {
client.removeListener('ready', handleReady);
reject(err);
client.removeListener('error', handleError);
reject(lastError);
}

client.once('ready', handleReady);
client.once('error', handleError);
client.on('error', handleError);
client.once('end', handleEnd);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions test/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ describe('connection', () => {
});
});

it('should fail if redis connection fails', done => {
it('should fail if redis connection fails and does not reconnect', done => {
queue = utils.buildQueue('connection fail', {
redis: {
host: 'localhost',
port: 1234
port: 1234,
retryStrategy: () => false
}
});

Expand Down
4 changes: 2 additions & 2 deletions test/test_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Queue', () => {

it('should create a queue with a redis connection string', () => {
const queue = new Queue('connstring', 'redis://123.4.5.67:1234/2', {
redis: { connectTimeout: 1000 }
redis: { connectTimeout: 1000, retryStrategy: () => false }
});

expect(queue.client.options.host).to.be.eql('123.4.5.67');
Expand All @@ -154,7 +154,7 @@ describe('Queue', () => {

it('should create a queue with only a hostname', () => {
const queue = new Queue('connstring', 'redis://127.2.3.4', {
redis: { connectTimeout: 1000 }
redis: { connectTimeout: 1000, retryStrategy: () => false }
});

expect(queue.client.options.host).to.be.eql('127.2.3.4');
Expand Down

0 comments on commit 0ca4c6b

Please sign in to comment.