File tree Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,14 @@ export default class RedisClient<
325
325
return this . _self . #watchEpoch !== undefined ;
326
326
}
327
327
328
+ get watchEpoch ( ) {
329
+ return this . _self . #watchEpoch
330
+ }
331
+
332
+ setWatchEpoch ( watchEpoch : number | undefined ) {
333
+ this . _self . #watchEpoch = watchEpoch
334
+ }
335
+
328
336
setDirtyWatch ( msg : string ) {
329
337
this . _self . #dirtyWatch = msg ;
330
338
}
Original file line number Diff line number Diff line change @@ -197,6 +197,11 @@ async function steadyState(frame: SentinelFramework) {
197
197
198
198
await assert . doesNotReject ( sentinel . get ( 'x' ) ) ;
199
199
} ) ;
200
+
201
+ it ( 'failed to connect' , async function ( ) {
202
+ sentinel = frame . getSentinelClient ( { sentinelRootNodes : [ { host : "127.0.0.1" , port : 1010 } ] , maxCommandRediscovers : 0 } )
203
+ await assert . rejects ( sentinel . connect ( ) ) ;
204
+ } ) ;
200
205
201
206
it ( 'try to connect multiple times' , async function ( ) {
202
207
sentinel = frame . getSentinelClient ( ) ;
Original file line number Diff line number Diff line change @@ -682,9 +682,10 @@ class RedisSentinelInternal<
682
682
683
683
async #connect( ) {
684
684
let count = 0 ;
685
- while ( true ) {
685
+ while ( true ) {
686
686
this . #trace( "starting connect loop" ) ;
687
687
688
+ count += 1 ;
688
689
if ( this . #destroy) {
689
690
this . #trace( "in #connect and want to destroy" )
690
691
return ;
@@ -1106,10 +1107,12 @@ class RedisSentinelInternal<
1106
1107
this . #trace( `transform: opening a new master` ) ;
1107
1108
const masterPromises = [ ] ;
1108
1109
const masterWatches : Array < boolean > = [ ] ;
1110
+ const watchEpochs : Array < number | undefined > = [ ] ;
1109
1111
1110
1112
this . #trace( `transform: destroying old masters if open` ) ;
1111
1113
for ( const client of this . #masterClients) {
1112
1114
masterWatches . push ( client . isWatching ) ;
1115
+ watchEpochs . push ( client . watchEpoch ) ;
1113
1116
1114
1117
if ( client . isOpen ) {
1115
1118
client . destroy ( )
@@ -1135,6 +1138,7 @@ class RedisSentinelInternal<
1135
1138
} ) ;
1136
1139
1137
1140
if ( masterWatches [ i ] ) {
1141
+ client . setWatchEpoch ( watchEpochs [ i ] )
1138
1142
client . setDirtyWatch ( "sentinel config changed in middle of a WATCH Transaction" ) ;
1139
1143
}
1140
1144
this . #masterClients. push ( client ) ;
Original file line number Diff line number Diff line change @@ -180,9 +180,14 @@ export class SentinelFramework extends DockerBase {
180
180
RedisScripts ,
181
181
RespVersions ,
182
182
TypeMapping > > , errors = true ) {
183
- if ( opts ?. sentinelRootNodes !== undefined ) {
184
- throw new Error ( "cannot specify sentinelRootNodes here" ) ;
185
- }
183
+ // remove this safeguard
184
+ // in order to test the case when
185
+ // connecting to sentinel fails
186
+
187
+ // if (opts?.sentinelRootNodes !== undefined) {
188
+ // throw new Error("cannot specify sentinelRootNodes here");
189
+ // }
190
+
186
191
if ( opts ?. name !== undefined ) {
187
192
throw new Error ( "cannot specify sentinel db name here" ) ;
188
193
}
You can’t perform that action at this time.
0 commit comments