This repository was archived by the owner on Oct 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff 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 }
@@ -20,6 +21,7 @@ export default function redisClient() { // eslint-disable-line no-unused-vars
2021
2122 client . on ( 'ready' , ( ) => {
2223 app . set ( 'redisClient' , client ) ;
24+ /* istanbul ignore next */
2325 if ( cacheOptions . env !== 'test' ) {
2426 console . log ( `${ chalk . green ( '[redis]' ) } connected` ) ;
2527 }
Original file line number Diff line number Diff line change @@ -634,6 +634,41 @@ describe('Redis After Hook', () => {
634634 } ) ;
635635 } ) ;
636636
637+ it ( 'does not save anything in cache if redisClient offline' , ( ) => {
638+ const hook = a ( ) ;
639+ const clientDummy = {
640+ keys : [ ] ,
641+ set : function ( key , val ) {
642+ this . keys . push ( key ) ;
643+ } ,
644+ expire : function ( ) { } ,
645+ rpush : function ( ) { } ,
646+ } ;
647+ const mock = {
648+ params : { query : '' } ,
649+ path : 'dummy' ,
650+ id : 'do-not-save' ,
651+ result : {
652+ cache : { }
653+ } ,
654+ app : {
655+ get : ( what ) => {
656+ // comment in to emulate redisClient online (will cause test fail)
657+ // if (what === 'redisClient') {
658+ // return clientDummy;
659+ // }
660+ }
661+ }
662+ } ;
663+ const prevKeys = clientDummy . keys . join ( ) ;
664+
665+ return hook ( mock ) . then ( result => {
666+ const currKeys = clientDummy . keys . join ( ) ;
667+
668+ expect ( currKeys ) . to . equal ( prevKeys ) ;
669+ } ) ;
670+ } ) ;
671+
637672 // after(() => {
638673 // client.del('parent');
639674 // client.del('parent?full=true');
Original file line number Diff line number Diff line change @@ -222,6 +222,24 @@ describe('Redis Before Hook', () => {
222222 } ) ;
223223 } ) ;
224224
225+ it ( 'does not return any result if redisClient offline' , ( ) => {
226+ const hook = b ( ) ;
227+ const mock = {
228+ params : { query : '' } ,
229+ path : '' ,
230+ id : '' ,
231+ app : {
232+ get : ( what ) => { }
233+ }
234+ } ;
235+
236+ return hook ( mock ) . then ( result => {
237+ const data = result . result ;
238+
239+ expect ( data ) . to . be . undefined ;
240+ } ) ;
241+ } ) ;
242+
225243 after ( ( ) => {
226244 client . del ( 'before-test-route' ) ;
227245 client . del ( 'before-test-route?full=true' ) ;
You can’t perform that action at this time.
0 commit comments