Skip to content

Commit

Permalink
Merge pull request #313 from raveljs/feature/dependency-bump
Browse files Browse the repository at this point in the history
Feature/dependency bump
  • Loading branch information
Ghnuberath authored Feb 6, 2021
2 parents dbd4097 + 2e86f49 commit 2971972
Show file tree
Hide file tree
Showing 7 changed files with 4,545 additions and 2,288 deletions.
3 changes: 2 additions & 1 deletion documentation.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Ravel API
version: 1.0.0-rc.12
version: 1.0.0-rc.13
favicon: assets/logo.png
versions:
- 1.0.0-rc.13
- 1.0.0-rc.12
- 1.0.0-rc.11
- 1.0.0-rc.10
Expand Down
3 changes: 2 additions & 1 deletion jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// from https://gist.github.com/vlasky/2ea30ce9923bd06c2ee100f2924991cc
process.setMaxListeners(50);
const EventEmitter = require('events').EventEmitter;
const originalAddListener = EventEmitter.prototype.addListener;
const addListener = function (type) {
originalAddListener.apply(this, arguments);

const numListeners = this.listeners(type).length;
const max = typeof this._maxListeners === 'number' ? this._maxListeners : 10;
const max = typeof this._maxListeners === 'number' ? this._maxListeners : 50;

if (max !== 0 && numListeners > max) {
const error = new Error('Too many listeners of type "' + type + '" added to EventEmitter. Max is ' + max + " and we've added " + numListeners + '.');
Expand Down
4 changes: 2 additions & 2 deletions jest/util/kvstore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ describe('Ravel', () => {

describe('util/kvstore', () => {
describe('retryStrategy', () => {
it('should return an error when redis refuses the connection', async () => {
it.only('should return an error when redis refuses the connection, and maximum retries have been exceeded', async () => {
await app.init();
const retryStrategy = require('../../lib/util/kvstore').retryStrategy(app);
expect(typeof retryStrategy).toBe('function');
expect(retryStrategy({ error: { code: 'ECONNREFUSED' } })).toBeInstanceOf(app.$err.General);
expect(retryStrategy({ error: { code: 'ECONNREFUSED' }, attempt: app.get('redis max retries') + 1 })).toBeInstanceOf(app.$err.General);
});

it('should log any errors on a connection', async () => {
Expand Down
14 changes: 5 additions & 9 deletions lib/util/kvstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const redis = require('redis');
function retryStrategy (ravelInstance) {
return function (options) {
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: ${code}.`);
return new $err.General(`Lost connection to redis: ${code}.`);
} else if (options.attempt > ravelInstance.get('redis max retries')) {
if (options.attempt > ravelInstance.get('redis max retries')) {
ravelInstance.$log.error(`Lost connection to redis: ${code}. Max retry attempts exceeded.`);
// End reconnecting with built in error
return new $err.General(
Expand Down Expand Up @@ -59,7 +55,6 @@ function createClient (ravelInstance, restrict = true) {
let client;
if (localRedis) {
const mock = require('redis-mock');
mock.removeAllListeners(); // redis-mock doesn't clean up after itself very well.
client = mock.createClient();
client.flushall(); // in case this has been required before
} else {
Expand All @@ -71,15 +66,16 @@ function createClient (ravelInstance, restrict = true) {
retry_strategy: retryStrategy(ravelInstance)
});
}
if (ravelInstance.get('redis password')) {
client.auth(ravelInstance.get('redis password'));
}
// log errors
client.on('error', (err) => {
// Use console if framework logging isn't available yet
ravelInstance.$log ? ravelInstance.$log.error(err) : console.error(err);
});

if (ravelInstance.get('redis password')) {
client.auth(ravelInstance.get('redis password'));
}

// keepalive when not testing
const redisKeepaliveInterval = setInterval(() => {
client && client.ping && client.ping();
Expand Down
1 change: 0 additions & 1 deletion lib/util/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const httpCodes = require('./http_codes');
*/
const buildRestResponse = function (ravelInstance, request, response, options) {
options = options || {};
// debugger;
if (options.okCode === undefined) {
if (response.body && request.method.toUpperCase() === 'POST') {
options.okCode = httpCodes.CREATED;
Expand Down
Loading

0 comments on commit 2971972

Please sign in to comment.