@@ -1274,9 +1274,12 @@ func TestGetNewFinshedPods(t *testing.T) {
1274
1274
1275
1275
func TestTrackJobStatusAndRemoveFinalizers (t * testing.T ) {
1276
1276
logger , ctx := ktesting .NewTestContext (t )
1277
- completedCond := newCondition (batch .JobComplete , v1 .ConditionTrue , "" , "" , realClock .Now ())
1278
- succeededCond := newCondition (batch .JobSuccessCriteriaMet , v1 .ConditionTrue , "" , "" , realClock .Now ())
1279
- failedCond := newCondition (batch .JobFailed , v1 .ConditionTrue , "" , "" , realClock .Now ())
1277
+ fakeClock := clocktesting .NewFakeClock (time .Now ())
1278
+ now := fakeClock .Now ()
1279
+ minuteAgo := now .Add (- time .Minute )
1280
+ completedCond := newCondition (batch .JobComplete , v1 .ConditionTrue , "" , "" , now )
1281
+ succeededCond := newCondition (batch .JobSuccessCriteriaMet , v1 .ConditionTrue , "" , "" , minuteAgo )
1282
+ failedCond := newCondition (batch .JobFailed , v1 .ConditionTrue , "" , "" , now )
1280
1283
indexedCompletion := batch .IndexedCompletion
1281
1284
mockErr := errors .New ("mock error" )
1282
1285
cases := map [string ]struct {
@@ -1443,7 +1446,7 @@ func TestTrackJobStatusAndRemoveFinalizers(t *testing.T) {
1443
1446
Succeeded : 1 ,
1444
1447
Failed : 1 ,
1445
1448
Conditions : []batch.JobCondition {* succeededCond , * completedCond },
1446
- CompletionTime : & succeededCond . LastTransitionTime ,
1449
+ CompletionTime : ptr . To ( metav1 . NewTime ( now )) ,
1447
1450
},
1448
1451
},
1449
1452
wantSucceededPodsMetric : 1 ,
@@ -1933,7 +1936,7 @@ func TestTrackJobStatusAndRemoveFinalizers(t *testing.T) {
1933
1936
defer featuregatetesting .SetFeatureGateDuringTest (t , feature .DefaultFeatureGate , features .JobSuccessPolicy , tc .enableJobSuccessPolicy )()
1934
1937
1935
1938
clientSet := clientset .NewForConfigOrDie (& restclient.Config {Host : "" , ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Group : "" , Version : "v1" }}})
1936
- manager , _ := newControllerFromClient (ctx , t , clientSet , controller .NoResyncPeriodFunc )
1939
+ manager , _ := newControllerFromClientWithClock (ctx , t , clientSet , controller .NoResyncPeriodFunc , fakeClock )
1937
1940
fakePodControl := controller.FakePodControl {Err : tc .podControlErr }
1938
1941
metrics .JobPodsFinished .Reset ()
1939
1942
manager .podControl = & fakePodControl
@@ -1966,24 +1969,10 @@ func TestTrackJobStatusAndRemoveFinalizers(t *testing.T) {
1966
1969
if ! errors .Is (err , tc .wantErr ) {
1967
1970
t .Errorf ("Got error %v, want %v" , err , tc .wantErr )
1968
1971
}
1969
- cmpOpts := []cmp.Option {cmpopts .IgnoreFields (batch.JobCondition {}, "LastProbeTime" , "LastTransitionTime" )}
1970
- if tc .finishedCond != nil && tc .finishedCond .Type == batch .JobSuccessCriteriaMet {
1971
- cmpOpts = append (cmpOpts , cmpopts .IgnoreFields (batch.JobStatus {}, "CompletionTime" ))
1972
- }
1973
- if diff := cmp .Diff (tc .wantStatusUpdates , statusUpdates , cmpOpts ... ); diff != "" {
1972
+ if diff := cmp .Diff (tc .wantStatusUpdates , statusUpdates ,
1973
+ cmpopts .IgnoreFields (batch.JobCondition {}, "LastProbeTime" , "LastTransitionTime" )); diff != "" {
1974
1974
t .Errorf ("Unexpected status updates (-want,+got):\n %s" , diff )
1975
1975
}
1976
- // If we set successCondition with the SuccessCriteriaMet, the job-controller adds the Complete condition to the Job while reconciling,
1977
- // then the added Complete condition LastTransitionTime is used as a CompletionTime.
1978
- // So, we verify if the CompletionTime is after the SuccessCriteriaMet LastTransitionTime.
1979
- if tc .finishedCond != nil && tc .finishedCond .Type == batch .JobSuccessCriteriaMet && len (tc .wantStatusUpdates ) != 0 {
1980
- for i := range tc .wantStatusUpdates {
1981
- if tc .wantStatusUpdates [i ].CompletionTime != nil && ! tc .wantStatusUpdates [i ].CompletionTime .Before (statusUpdates [i ].CompletionTime ) {
1982
- t .Errorf ("Unexpected completionTime; completionTime %v must be after %v" ,
1983
- tc .wantStatusUpdates [i ].CompletionTime , statusUpdates [i ].CompletionTime )
1984
- }
1985
- }
1986
- }
1987
1976
rmFinalizers := len (fakePodControl .Patches )
1988
1977
if rmFinalizers != tc .wantRmFinalizers {
1989
1978
t .Errorf ("Removed %d finalizers, want %d" , rmFinalizers , tc .wantRmFinalizers )
0 commit comments