@@ -268,6 +268,48 @@ func TestSuccessThreshold(t *testing.T) {
268
268
}
269
269
}
270
270
271
+ func TestStartupProbeSuccessThreshold (t * testing.T ) {
272
+ ctx := context .Background ()
273
+ m := newTestManager ()
274
+ successThreshold := 1
275
+ failureThreshold := 3
276
+ w := newTestWorker (m , startup , v1.Probe {SuccessThreshold : int32 (successThreshold ), FailureThreshold : int32 (failureThreshold )})
277
+ m .statusManager .SetPodStatus (w .pod , getTestNotRunningStatus ())
278
+
279
+ m .prober .exec = fakeExecProber {probe .Success , nil }
280
+
281
+ for i := 0 ; i < successThreshold + 1 ; i ++ {
282
+ msg := fmt .Sprintf ("%d success" , successThreshold )
283
+ expectContinue (t , w , w .doProbe (ctx ), msg )
284
+ expectResult (t , w , results .Success , msg )
285
+ expectResultRun (t , w , 0 , msg )
286
+ }
287
+ }
288
+
289
+ func TestStartupProbeFailureThreshold (t * testing.T ) {
290
+ ctx := context .Background ()
291
+ m := newTestManager ()
292
+ successThreshold := 1
293
+ failureThreshold := 3
294
+ w := newTestWorker (m , startup , v1.Probe {SuccessThreshold : int32 (successThreshold ), FailureThreshold : int32 (failureThreshold )})
295
+ m .statusManager .SetPodStatus (w .pod , getTestNotRunningStatus ())
296
+
297
+ m .prober .exec = fakeExecProber {probe .Failure , nil }
298
+
299
+ for i := 0 ; i < failureThreshold + 1 ; i ++ {
300
+ msg := fmt .Sprintf ("%d failure" , i + 1 )
301
+ expectContinue (t , w , w .doProbe (ctx ), msg )
302
+ if i < failureThreshold - 1 {
303
+ expectResult (t , w , results .Unknown , msg )
304
+ expectResultRun (t , w , i + 1 , msg )
305
+ } else {
306
+ msg := fmt .Sprintf ("%d failure" , failureThreshold )
307
+ expectResult (t , w , results .Failure , msg )
308
+ expectResultRun (t , w , 0 , msg )
309
+ }
310
+ }
311
+ }
312
+
271
313
func TestCleanUp (t * testing.T ) {
272
314
m := newTestManager ()
273
315
@@ -315,6 +357,13 @@ func expectResult(t *testing.T, w *worker, expectedResult results.Result, msg st
315
357
}
316
358
}
317
359
360
+ func expectResultRun (t * testing.T , w * worker , expectedResultRun int , msg string ) {
361
+ if w .resultRun != expectedResultRun {
362
+ t .Errorf ("[%s - %s] Expected result to be %v, but was %v" ,
363
+ w .probeType , msg , expectedResultRun , w .resultRun )
364
+ }
365
+ }
366
+
318
367
func expectContinue (t * testing.T , w * worker , c bool , msg string ) {
319
368
if ! c {
320
369
t .Errorf ("[%s - %s] Expected to continue, but did not" , w .probeType , msg )
@@ -366,8 +415,10 @@ func TestOnHoldOnLivenessOrStartupCheckFailure(t *testing.T) {
366
415
msg = "hold lifted"
367
416
expectContinue (t , w , w .doProbe (ctx ), msg )
368
417
expectResult (t , w , results .Success , msg )
369
- if w .onHold {
418
+ if probeType == liveness && w .onHold {
370
419
t .Errorf ("Prober should not be on hold anymore" )
420
+ } else if probeType == startup && ! w .onHold {
421
+ t .Errorf ("Prober should be on hold due to %s check success" , probeType )
371
422
}
372
423
}
373
424
}
0 commit comments