mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Ensure job is up to date in informer cache in test
The fake client doesn't guarantee that the informer cache is updated. If it's not up-to-date, the controller always tries to set the StartTime, leading to a broken test. Change-Id: I71f26d46ea44beff88f0d03517985348654aec95
This commit is contained in:
parent
00cd2ae3bc
commit
4c1b95ddfa
@ -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{})
|
||||
|
Loading…
Reference in New Issue
Block a user