@@ -284,19 +284,19 @@ func TestStartupProbeSuccessThreshold(t *testing.T) {
284
284
if w .onHold {
285
285
t .Errorf ("Prober should not be on hold" )
286
286
}
287
+ msg := fmt .Sprintf ("%d success" , i + 1 )
288
+ expectContinue (t , w , w .doProbe (ctx ), msg )
289
+ expectResult (t , w , results .Success , msg )
287
290
} else {
288
291
// Probe should be on hold and will not be executed anymore
289
292
// when successThreshold is met
290
293
if ! w .onHold {
291
294
t .Errorf ("Prober should be on hold because successThreshold is exceeded" )
292
295
}
293
- }
294
- msg := fmt .Sprintf ("%d success" , successThreshold )
295
- expectContinue (t , w , w .doProbe (ctx ), msg )
296
- expectResult (t , w , results .Success , 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 )
296
+ // Meeting or exceeding successThreshold should cause resultRun to reset to 0
297
+ if w .resultRun != 0 {
298
+ t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
299
+ }
300
300
}
301
301
}
302
302
}
@@ -311,41 +311,40 @@ func TestStartupProbeFailureThreshold(t *testing.T) {
311
311
m .prober .exec = fakeExecProber {probe .Failure , nil }
312
312
313
313
for i := 0 ; i < failureThreshold + 1 ; i ++ {
314
- if i < failureThreshold - 1 {
314
+ if i < failureThreshold {
315
315
// Probe should not be on hold and will continue to be excuted
316
316
// until failureThreshold is met
317
317
if w .onHold {
318
318
t .Errorf ("Prober should not be on hold" )
319
319
}
320
320
msg := fmt .Sprintf ("%d failure" , i + 1 )
321
321
expectContinue (t , w , w .doProbe (ctx ), msg )
322
- expectResult (t , w , results .Unknown , 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 )
322
+ switch i {
323
+ case 0 , 1 :
324
+ // At this point, the expected result is Unknown
325
+ // because w.resultsManager.Set() will be called after FailureThreshold is reached
326
+ expectResult (t , w , results .Unknown , msg )
327
+ // resultRun should be incremented until failureThreshold is met
328
+ if w .resultRun != i + 1 {
329
+ t .Errorf ("Prober resultRun should be %d, but %d" , i + 1 , w .resultRun )
330
+ }
331
+ case 2 :
332
+ // The expected result is Failure
333
+ // because w.resultsManager.Set() will be called due to resultRun reaching failureThreshold,
334
+ // updating the cached result to Failure.
335
+ // After that, resultRun will be reset to 0.
336
+ expectResult (t , w , results .Failure , msg )
337
+ // Meeting failureThreshold should cause resultRun to reset to 0
338
+ if w .resultRun != 0 {
339
+ t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
340
+ }
339
341
}
340
342
} else {
341
343
// Probe should be on hold and will not be executed anymore
342
344
// when failureThreshold is met
343
345
if ! w .onHold {
344
346
t .Errorf ("Prober should be on hold because failureThreshold is exceeded" )
345
347
}
346
- msg := fmt .Sprintf ("%d failure" , failureThreshold )
347
- expectContinue (t , w , w .doProbe (ctx ), msg )
348
- expectResult (t , w , results .Failure , msg )
349
348
// Exceeding failureThreshold should cause resultRun to reset to 0
350
349
if w .resultRun != 0 {
351
350
t .Errorf ("Prober resultRun should be 0, but %d" , w .resultRun )
0 commit comments