Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 93bb3a2

Browse files
committed
Merge branch 'SassNinja-fix/connection-error'
2 parents 521f938 + a62c137 commit 93bb3a2

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/redisClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default function redisClient() { // eslint-disable-line no-unused-vars
88
const redisOptions = Object.assign({}, this.get('redis'), {
99
retry_strategy: function (options) { // eslint-disable-line camelcase
1010
app.set('redisClient', undefined);
11+
/* istanbul ignore next */
1112
if (cacheOptions.env !== 'test') {
1213
console.log(`${chalk.yellow('[redis]')} not connected`);
1314
}
@@ -16,8 +17,11 @@ export default function redisClient() { // eslint-disable-line no-unused-vars
1617
});
1718
const client = redis.createClient(redisOptions);
1819

20+
app.set('redisClient', client);
21+
1922
client.on('ready', () => {
2023
app.set('redisClient', client);
24+
/* istanbul ignore next */
2125
if (cacheOptions.env !== 'test') {
2226
console.log(`${chalk.green('[redis]')} connected`);
2327
}

test/hooks/redis-after.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,41 @@ describe('Redis After Hook', () => {
666666
});
667667
});
668668

669+
it ('does not save anything in cache if redisClient offline', () => {
670+
const hook = a();
671+
const clientDummy = {
672+
keys: [],
673+
set: function(key, val) {
674+
this.keys.push(key);
675+
},
676+
expire: function() {},
677+
rpush: function() {},
678+
};
679+
const mock = {
680+
params: { query: '' },
681+
path: 'dummy',
682+
id: 'do-not-save',
683+
result: {
684+
cache: {}
685+
},
686+
app: {
687+
get: (what) => {
688+
// comment in to emulate redisClient online (will cause test fail)
689+
// if (what === 'redisClient') {
690+
// return clientDummy;
691+
// }
692+
}
693+
}
694+
};
695+
const prevKeys = clientDummy.keys.join();
696+
697+
return hook(mock).then(result => {
698+
const currKeys = clientDummy.keys.join();
699+
700+
expect(currKeys).to.equal(prevKeys);
701+
});
702+
});
703+
669704
// after(() => {
670705
// client.del('parent');
671706
// client.del('parent?full=true');

test/hooks/redis-before.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,24 @@ describe('Redis Before Hook', () => {
240240
});
241241
});
242242

243+
it('does not return any result if redisClient offline', () => {
244+
const hook = b();
245+
const mock = {
246+
params: { query: ''},
247+
path: '',
248+
id: '',
249+
app: {
250+
get: (what) => {}
251+
}
252+
};
253+
254+
return hook(mock).then(result => {
255+
const data = result.result;
256+
257+
expect(data).to.be.undefined;
258+
});
259+
});
260+
243261
after(() => {
244262
client.del('before-test-route');
245263
client.del('before-test-route?full=true');

0 commit comments

Comments
 (0)