@@ -5206,20 +5206,23 @@ func Test_Ingester_ModeHandler(t *testing.T) {
5206
5206
mode string
5207
5207
expectedState ring.InstanceState
5208
5208
expectedResponse int
5209
+ expectedIsReady bool
5209
5210
}{
5210
5211
"should change to READONLY mode" : {
5211
5212
method : "POST" ,
5212
5213
initialState : ring .ACTIVE ,
5213
5214
requestUrl : "/mode?mode=reAdOnLy" ,
5214
5215
expectedState : ring .READONLY ,
5215
5216
expectedResponse : http .StatusOK ,
5217
+ expectedIsReady : true ,
5216
5218
},
5217
5219
"should change mode on GET method" : {
5218
5220
method : "GET" ,
5219
5221
initialState : ring .ACTIVE ,
5220
5222
requestUrl : "/mode?mode=READONLY" ,
5221
5223
expectedState : ring .READONLY ,
5222
5224
expectedResponse : http .StatusOK ,
5225
+ expectedIsReady : true ,
5223
5226
},
5224
5227
"should change mode on POST method via body" : {
5225
5228
method : "POST" ,
@@ -5228,53 +5231,61 @@ func Test_Ingester_ModeHandler(t *testing.T) {
5228
5231
requestBody : strings .NewReader ("mode=readonly" ),
5229
5232
expectedState : ring .READONLY ,
5230
5233
expectedResponse : http .StatusOK ,
5234
+ expectedIsReady : true ,
5231
5235
},
5232
5236
"should change to ACTIVE mode" : {
5233
5237
method : "POST" ,
5234
5238
initialState : ring .READONLY ,
5235
5239
requestUrl : "/mode?mode=active" ,
5236
5240
expectedState : ring .ACTIVE ,
5237
5241
expectedResponse : http .StatusOK ,
5242
+ expectedIsReady : true ,
5238
5243
},
5239
5244
"should fail to unknown mode" : {
5240
5245
method : "POST" ,
5241
5246
initialState : ring .ACTIVE ,
5242
5247
requestUrl : "/mode?mode=NotSupported" ,
5243
5248
expectedState : ring .ACTIVE ,
5244
5249
expectedResponse : http .StatusBadRequest ,
5250
+ expectedIsReady : true ,
5245
5251
},
5246
5252
"should maintain in readonly" : {
5247
5253
method : "POST" ,
5248
5254
initialState : ring .READONLY ,
5249
5255
requestUrl : "/mode?mode=READONLY" ,
5250
5256
expectedState : ring .READONLY ,
5251
5257
expectedResponse : http .StatusOK ,
5258
+ expectedIsReady : true ,
5252
5259
},
5253
5260
"should maintain in active" : {
5254
5261
method : "POST" ,
5255
5262
initialState : ring .ACTIVE ,
5256
5263
requestUrl : "/mode?mode=ACTIVE" ,
5257
5264
expectedState : ring .ACTIVE ,
5258
5265
expectedResponse : http .StatusOK ,
5266
+ expectedIsReady : true ,
5259
5267
},
5260
5268
"should fail mode READONLY if LEAVING state" : {
5261
5269
method : "POST" ,
5262
5270
initialState : ring .LEAVING ,
5263
5271
requestUrl : "/mode?mode=READONLY" ,
5264
5272
expectedState : ring .LEAVING ,
5265
5273
expectedResponse : http .StatusBadRequest ,
5274
+ expectedIsReady : false ,
5266
5275
},
5267
5276
"should fail with malformatted request" : {
5268
5277
method : "GET" ,
5269
5278
initialState : ring .ACTIVE ,
5270
5279
requestUrl : "/mode?mod;e=READONLY" ,
5271
5280
expectedResponse : http .StatusBadRequest ,
5281
+ expectedIsReady : true ,
5272
5282
},
5273
5283
}
5274
5284
5275
5285
for testName , testData := range tests {
5276
5286
t .Run (testName , func (t * testing.T ) {
5277
5287
cfg := defaultIngesterTestConfig (t )
5288
+ cfg .LifecyclerConfig .MinReadyDuration = 0
5278
5289
i , err := prepareIngesterWithBlocksStorage (t , cfg , prometheus .NewRegistry ())
5279
5290
require .NoError (t , err )
5280
5291
require .NoError (t , services .StartAndAwaitRunning (context .Background (), i ))
@@ -5304,6 +5315,13 @@ func Test_Ingester_ModeHandler(t *testing.T) {
5304
5315
5305
5316
require .Equal (t , testData .expectedResponse , response .Code )
5306
5317
require .Equal (t , testData .expectedState , i .lifecycler .GetState ())
5318
+
5319
+ err = i .CheckReady (context .Background ())
5320
+ if testData .expectedIsReady {
5321
+ require .NoError (t , err )
5322
+ } else {
5323
+ require .NotNil (t , err )
5324
+ }
5307
5325
})
5308
5326
}
5309
5327
}
0 commit comments