func TestInitialDelay(t *testing.T) { m := newTestManager() for _, probeType := range [...]probeType{liveness, readiness} { w := newTestWorker(m, probeType, api.Probe{ InitialDelaySeconds: 10, }) m.statusManager.SetPodStatus(w.pod, getRunningStatus()) if !w.doProbe() { t.Errorf("[%s] Expected to continue, but did not", probeType) } expectedResult := results.Result(probeType == liveness) result, ok := resultsManager(m, probeType).Get(containerID) if !ok { t.Errorf("[%s] Expected result to be set during initial delay, but was not set", probeType) } else if result != expectedResult { t.Errorf("[%s] Expected result to be %v during initial delay, but was %v", probeType, expectedResult, result) } // 100 seconds later... laterStatus := getRunningStatus() laterStatus.ContainerStatuses[0].State.Running.StartedAt.Time = time.Now().Add(-100 * time.Second) m.statusManager.SetPodStatus(w.pod, laterStatus) // Second call should succeed (already waited). if !w.doProbe() { t.Errorf("[%s] Expected to continue, but did not", probeType) } result, ok = resultsManager(m, probeType).Get(containerID) if !ok { t.Errorf("[%s] Expected result to be true, but was not set", probeType) } else if !result { t.Errorf("[%s] Expected result to be true, but was false", probeType) } } }
func TestInitialDelay(t *testing.T) { m := newTestManager() for _, probeType := range [...]probeType{liveness, readiness} { w := newTestWorker(m, probeType, api.Probe{ InitialDelaySeconds: 10, }) m.statusManager.SetPodStatus(w.pod, getTestRunningStatus()) expectContinue(t, w, w.doProbe(), "during initial delay") expectResult(t, w, results.Result(probeType == liveness), "during initial delay") // 100 seconds later... laterStatus := getTestRunningStatus() laterStatus.ContainerStatuses[0].State.Running.StartedAt.Time = time.Now().Add(-100 * time.Second) m.statusManager.SetPodStatus(w.pod, laterStatus) // Second call should succeed (already waited). expectContinue(t, w, w.doProbe(), "after initial delay") expectResult(t, w, results.Success, "after initial delay") } }