@@ -275,14 +275,29 @@ func TestStartupProbeSuccessThreshold(t *testing.T) {
275
275
failureThreshold := 3
276
276
w := newTestWorker (m , startup , v1.Probe {SuccessThreshold : int32 (successThreshold ), FailureThreshold : int32 (failureThreshold )})
277
277
m .statusManager .SetPodStatus (w .pod , getTestNotRunningStatus ())
278
-
279
278
m .prober .exec = fakeExecProber {probe .Success , nil }
280
279
281
280
for i := 0 ; i < successThreshold + 1 ; i ++ {
281
+ if i < successThreshold {
282
+ // Probe should not be on hold and will continue to be excuted
283
+ // until successThreshold is met
284
+ if w .onHold {
285
+ t .Errorf ("Prober should not be on hold" )
286
+ }
287
+ } else {
288
+ // Probe should be on hold and will not be executed anymore
289
+ // when successThreshold is met
290
+ if ! w .onHold {
291
+ t .Errorf ("Prober should be on hold because successThreshold is exceeded" )
292
+ }
293
+ }
282
294
msg := fmt .Sprintf ("%d success" , successThreshold )
283
295
expectContinue (t , w , w .doProbe (ctx ), msg )
284
296
expectResult (t , w , results .Success , msg )
285
- expectResultRun (t , w , 0 , msg )
297
+ // Meeting or exceeding successThreshold should cause resultRun to reset to 0
298
+ if w .resultRun != 0 {
299
+ t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
300
+ }
286
301
}
287
302
}
288
303
@@ -293,19 +308,48 @@ func TestStartupProbeFailureThreshold(t *testing.T) {
293
308
failureThreshold := 3
294
309
w := newTestWorker (m , startup , v1.Probe {SuccessThreshold : int32 (successThreshold ), FailureThreshold : int32 (failureThreshold )})
295
310
m .statusManager .SetPodStatus (w .pod , getTestNotRunningStatus ())
296
-
297
311
m .prober .exec = fakeExecProber {probe .Failure , nil }
298
312
299
313
for i := 0 ; i < failureThreshold + 1 ; i ++ {
300
- msg := fmt .Sprintf ("%d failure" , i + 1 )
301
- expectContinue (t , w , w .doProbe (ctx ), msg )
302
314
if i < failureThreshold - 1 {
315
+ // Probe should not be on hold and will continue to be excuted
316
+ // until failureThreshold is met
317
+ if w .onHold {
318
+ t .Errorf ("Prober should not be on hold" )
319
+ }
320
+ msg := fmt .Sprintf ("%d failure" , i + 1 )
321
+ expectContinue (t , w , w .doProbe (ctx ), msg )
303
322
expectResult (t , w , results .Unknown , msg )
304
- expectResultRun (t , w , i + 1 , msg )
323
+ // resultRun should be incremented until failureThreshold is met
324
+ if w .resultRun != i + 1 {
325
+ t .Errorf ("Prober resultRun should be %d, but %d" , i + 1 , w .resultRun )
326
+ }
327
+ } else if i < failureThreshold {
328
+ // Probe should not be on hold and will continue to be excuted
329
+ // until failureThreshold is met
330
+ if w .onHold {
331
+ t .Errorf ("Prober should not be on hold" )
332
+ }
333
+ msg := fmt .Sprintf ("%d failure" , i + 1 )
334
+ expectContinue (t , w , w .doProbe (ctx ), msg )
335
+ expectResult (t , w , results .Failure , msg )
336
+ // Meeting failureThreshold should cause resultRun to reset to 0
337
+ if w .resultRun != 0 {
338
+ t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
339
+ }
305
340
} else {
341
+ // Probe should be on hold and will not be executed anymore
342
+ // when failureThreshold is met
343
+ if ! w .onHold {
344
+ t .Errorf ("Prober should be on hold because failureThreshold is exceeded" )
345
+ }
306
346
msg := fmt .Sprintf ("%d failure" , failureThreshold )
347
+ expectContinue (t , w , w .doProbe (ctx ), msg )
307
348
expectResult (t , w , results .Failure , msg )
308
- expectResultRun (t , w , 0 , msg )
349
+ // Exceeding failureThreshold should cause resultRun to reset to 0
350
+ if w .resultRun != 0 {
351
+ t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
352
+ }
309
353
}
310
354
}
311
355
}
@@ -357,13 +401,6 @@ func expectResult(t *testing.T, w *worker, expectedResult results.Result, msg st
357
401
}
358
402
}
359
403
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
-
367
404
func expectContinue (t * testing.T , w * worker , c bool , msg string ) {
368
405
if ! c {
369
406
t .Errorf ("[%s - %s] Expected to continue, but did not" , w .probeType , msg )
0 commit comments