Skip to content

Commit 632f162

Browse files
committed
fix unit test
1 parent a262c80 commit 632f162

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

pkg/kubelet/prober/worker_test.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,19 @@ func TestStartupProbeSuccessThreshold(t *testing.T) {
284284
if w.onHold {
285285
t.Errorf("Prober should not be on hold")
286286
}
287+
msg := fmt.Sprintf("%d success", i+1)
288+
expectContinue(t, w, w.doProbe(ctx), msg)
289+
expectResult(t, w, results.Success, msg)
287290
} else {
288291
// Probe should be on hold and will not be executed anymore
289292
// when successThreshold is met
290293
if !w.onHold {
291294
t.Errorf("Prober should be on hold because successThreshold is exceeded")
292295
}
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+
}
300300
}
301301
}
302302
}
@@ -311,41 +311,40 @@ func TestStartupProbeFailureThreshold(t *testing.T) {
311311
m.prober.exec = fakeExecProber{probe.Failure, nil}
312312

313313
for i := 0; i < failureThreshold+1; i++ {
314-
if i < failureThreshold-1 {
314+
if i < failureThreshold {
315315
// Probe should not be on hold and will continue to be excuted
316316
// until failureThreshold is met
317317
if w.onHold {
318318
t.Errorf("Prober should not be on hold")
319319
}
320320
msg := fmt.Sprintf("%d failure", i+1)
321321
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+
}
339341
}
340342
} else {
341343
// Probe should be on hold and will not be executed anymore
342344
// when failureThreshold is met
343345
if !w.onHold {
344346
t.Errorf("Prober should be on hold because failureThreshold is exceeded")
345347
}
346-
msg := fmt.Sprintf("%d failure", failureThreshold)
347-
expectContinue(t, w, w.doProbe(ctx), msg)
348-
expectResult(t, w, results.Failure, msg)
349348
// Exceeding failureThreshold should cause resultRun to reset to 0
350349
if w.resultRun != 0 {
351350
t.Errorf("Prober resultRun should be 0, but %d", w.resultRun)

0 commit comments

Comments
 (0)