diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index b52e36c1201..e286fd8c207 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -1664,6 +1664,7 @@ func TestTrackJobStatusAndRemoveFinalizers(t *testing.T) { } } +// TestSyncJobPastDeadline verifies tracking of active deadline in a single syncJob call. func TestSyncJobPastDeadline(t *testing.T) { testCases := map[string]struct { // job setup @@ -1829,7 +1830,9 @@ func hasTrueCondition(job *batch.Job) *batch.JobConditionType { return nil } -func TestSyncPastDeadlineJobFinished(t *testing.T) { +// TestPastDeadlineJobFinished ensures that a Job is correctly tracked until +// reaching the active deadline, at which point it is marked as Failed. +func TestPastDeadlineJobFinished(t *testing.T) { clientset := fake.NewSimpleClientset() fakeClock := clocktesting.NewFakeClock(time.Now().Truncate(time.Second)) manager, sharedInformerFactory := newControllerFromClientWithClock(clientset, controller.NoResyncPeriodFunc, fakeClock) @@ -1863,7 +1866,7 @@ func TestSyncPastDeadlineJobFinished(t *testing.T) { job := newJobWithName(tc.jobName, 1, 1, 6, batch.NonIndexedCompletion) job.Spec.ActiveDeadlineSeconds = pointer.Int64(1) if tc.setStartTime { - start := metav1.NewTime(fakeClock.Now().Add(-time.Second)) + start := metav1.NewTime(fakeClock.Now()) job.Status.StartTime = &start } @@ -1893,6 +1896,10 @@ func TestSyncPastDeadlineJobFinished(t *testing.T) { break } } + // Make sure the start time is in the informer cache. + if err := sharedInformerFactory.Batch().V1().Jobs().Informer().GetIndexer().Add(j); err != nil { + t.Fatalf("Failed to update job in cache: %v", err) + } manager.clock.Sleep(time.Second) err = wait.Poll(200*time.Millisecond, 3*time.Second, func() (done bool, err error) { j, err = clientset.BatchV1().Jobs(metav1.NamespaceDefault).Get(ctx, job.GetName(), metav1.GetOptions{})