diff --git a/documentation.yml b/documentation.yml index a383bac9..9670e6f4 100644 --- a/documentation.yml +++ b/documentation.yml @@ -1,6 +1,7 @@ name: Ravel API -version: 0.22.1 +version: 0.22.2 versions: + - 0.22.1 - 0.22.0 - 0.21.1 - 0.21.0 diff --git a/lib/util/kvstore.js b/lib/util/kvstore.js index f2068aa8..a039b416 100644 --- a/lib/util/kvstore.js +++ b/lib/util/kvstore.js @@ -8,18 +8,19 @@ const redis = require('redis'); */ function retryStrategy (ravelInstance) { return function (options) { - if (options.error && options.error.code === 'ECONNREFUSED') { + const code = options.error ? options.error.code : 'Reason Unknown'; + if (code === 'ECONNREFUSED') { // End reconnecting on a specific error and flush all commands with a individual error - ravelInstance.log.error(`Lost connection to redis: ${options.error.code}.`); - return new ApplicationError.General(`Lost connection to redis: ${options.error.code}.`); + ravelInstance.log.error(`Lost connection to redis: ${code}.`); + return new ApplicationError.General(`Lost connection to redis: ${code}.`); } else if (options.attempt > ravelInstance.get('redis max retries')) { - ravelInstance.log.error(`Lost connection to redis: ${options.error.code}. Max retry attempts exceeded.`); + ravelInstance.log.error(`Lost connection to redis: ${code}. Max retry attempts exceeded.`); // End reconnecting with built in error return new ApplicationError.General( - `Lost connection to redis: ${options.error.code}. Max retry attempts reached.`); + `Lost connection to redis: ${code}. Max retry attempts reached.`); } else { const time = Math.pow(options.attempt, 2) * 100; - ravelInstance.log.error(`Lost connection to redis: ${options.error.code}. Reconnecting in ${time} milliseconds.`); + ravelInstance.log.error(`Lost connection to redis: ${code}. Reconnecting in ${time} milliseconds.`); // reconnect after return time; } diff --git a/package.json b/package.json index 6f273c35..a82be1f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ravel", - "version": "0.22.1", + "version": "0.22.2", "author": "Sean McIntyre ", "description": "Ravel Rapid Application Development Framework", "engines": { diff --git a/test/util/test-kvstore.js b/test/util/test-kvstore.js index 35fea7ee..307bd17b 100644 --- a/test/util/test-kvstore.js +++ b/test/util/test-kvstore.js @@ -63,6 +63,19 @@ describe('Ravel', () => { done(); }); + it('should return an error when the maximum number of retries is exceeded without a reason', (done) => { + const retryStrategy = require('../../lib/util/kvstore').retryStrategy(Ravel); + expect(retryStrategy).to.be.a('function'); + Ravel.set('redis max retries', 10); + Ravel[coreSymbols.parametersLoaded] = true; + const options = { + error: undefined, + attempt: Ravel.get('redis max retries') + 1 + }; + expect(retryStrategy(options)).to.be.an.instanceof(Ravel.ApplicationError.General); + done(); + }); + it('should return the time to the next reconnect if the number of retries does not exceed the maximum', (done) => { const retryStrategy = require('../../lib/util/kvstore').retryStrategy(Ravel); expect(retryStrategy).to.be.a('function'); @@ -75,6 +88,19 @@ describe('Ravel', () => { expect(retryStrategy(options)).to.equal(100); done(); }); + + it('should return the time to the next reconnect if the number of retries does not exceed the maximum, and there was no reason for the error', (done) => { + const retryStrategy = require('../../lib/util/kvstore').retryStrategy(Ravel); + expect(retryStrategy).to.be.a('function'); + Ravel.set('redis max retries', 10); + Ravel[coreSymbols.parametersLoaded] = true; + const options = { + error: undefined, + attempt: 1 + }; + expect(retryStrategy(options)).to.equal(100); + done(); + }); }); }); });