Skip to content

Commit ead2102

Browse files
committed
add threshold check using w.onHold
1 parent 11ddb97 commit ead2102

File tree

1 file changed

+51
-14
lines changed

1 file changed

+51
-14
lines changed

pkg/kubelet/prober/worker_test.go

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,29 @@ func TestStartupProbeSuccessThreshold(t *testing.T) {
275275
failureThreshold := 3
276276
w := newTestWorker(m, startup, v1.Probe{SuccessThreshold: int32(successThreshold), FailureThreshold: int32(failureThreshold)})
277277
m.statusManager.SetPodStatus(w.pod, getTestNotRunningStatus())
278-
279278
m.prober.exec = fakeExecProber{probe.Success, nil}
280279

281280
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+
}
282294
msg := fmt.Sprintf("%d success", successThreshold)
283295
expectContinue(t, w, w.doProbe(ctx), msg)
284296
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+
}
286301
}
287302
}
288303

@@ -293,19 +308,48 @@ func TestStartupProbeFailureThreshold(t *testing.T) {
293308
failureThreshold := 3
294309
w := newTestWorker(m, startup, v1.Probe{SuccessThreshold: int32(successThreshold), FailureThreshold: int32(failureThreshold)})
295310
m.statusManager.SetPodStatus(w.pod, getTestNotRunningStatus())
296-
297311
m.prober.exec = fakeExecProber{probe.Failure, nil}
298312

299313
for i := 0; i < failureThreshold+1; i++ {
300-
msg := fmt.Sprintf("%d failure", i+1)
301-
expectContinue(t, w, w.doProbe(ctx), msg)
302314
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)
303322
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+
}
305340
} 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+
}
306346
msg := fmt.Sprintf("%d failure", failureThreshold)
347+
expectContinue(t, w, w.doProbe(ctx), msg)
307348
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+
}
309353
}
310354
}
311355
}
@@ -357,13 +401,6 @@ func expectResult(t *testing.T, w *worker, expectedResult results.Result, msg st
357401
}
358402
}
359403

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-
367404
func expectContinue(t *testing.T, w *worker, c bool, msg string) {
368405
if !c {
369406
t.Errorf("[%s - %s] Expected to continue, but did not", w.probeType, msg)

0 commit comments

Comments
 (0)