mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #114876 from alculquicondor/fix-deadline-test
Ensure job is up to date in informer cache in test
This commit is contained in:
commit
bea405c581
@ -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