@@ -214,6 +214,7 @@ func TestDeletePodsAndServices(t *testing.T) {
214
214
activeMasterServices int32
215
215
216
216
expectedPodDeletions int
217
+ expectedServiceDeletions int
217
218
}
218
219
219
220
testCases := []testCase {
@@ -235,6 +236,7 @@ func TestDeletePodsAndServices(t *testing.T) {
235
236
activeMasterServices : 1 ,
236
237
237
238
expectedPodDeletions : 5 ,
239
+ expectedServiceDeletions : 1 ,
238
240
},
239
241
testCase {
240
242
description : "4 workers and 1 master succeeded, policy is None" ,
@@ -254,6 +256,7 @@ func TestDeletePodsAndServices(t *testing.T) {
254
256
activeMasterServices : 1 ,
255
257
256
258
expectedPodDeletions : 0 ,
259
+ expectedServiceDeletions : 0 ,
257
260
},
258
261
}
259
262
for _ , tc := range testCases {
@@ -315,7 +318,6 @@ func TestDeletePodsAndServices(t *testing.T) {
315
318
testutil .SetPodsStatuses (podIndexer , tc .job , testutil .LabelMaster , tc .pendingMasterPods , tc .activeMasterPods , tc .succeededMasterPods , tc .failedMasterPods , nil , t )
316
319
317
320
serviceIndexer := kubeInformerFactory .Core ().V1 ().Services ().Informer ().GetIndexer ()
318
- testutil .SetServices (serviceIndexer , tc .job , testutil .LabelWorker , tc .activeWorkerServices , t )
319
321
testutil .SetServices (serviceIndexer , tc .job , testutil .LabelMaster , tc .activeMasterServices , t )
320
322
321
323
forget , err := ctr .syncPyTorchJob (testutil .GetKey (tc .job , t ))
@@ -329,8 +331,8 @@ func TestDeletePodsAndServices(t *testing.T) {
329
331
if len (fakePodControl .DeletePodName ) != tc .expectedPodDeletions {
330
332
t .Errorf ("%s: unexpected number of pod deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakePodControl .DeletePodName ))
331
333
}
332
- if len (fakeServiceControl .DeleteServiceName ) != tc .expectedPodDeletions {
333
- t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakeServiceControl .DeleteServiceName ))
334
+ if len (fakeServiceControl .DeleteServiceName ) != tc .expectedServiceDeletions {
335
+ t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedServiceDeletions , len (fakeServiceControl .DeleteServiceName ))
334
336
}
335
337
}
336
338
}
@@ -413,7 +415,7 @@ func TestCleanupPyTorchJob(t *testing.T) {
413
415
succeededMasterPods : 1 ,
414
416
failedMasterPods : 0 ,
415
417
416
- activeWorkerServices : 4 ,
418
+
417
419
activeMasterServices : 1 ,
418
420
419
421
expectedDeleteFinished : true ,
@@ -485,7 +487,6 @@ func TestCleanupPyTorchJob(t *testing.T) {
485
487
testutil .SetPodsStatuses (podIndexer , tc .job , testutil .LabelMaster , tc .pendingMasterPods , tc .activeMasterPods , tc .succeededMasterPods , tc .failedMasterPods , nil , t )
486
488
487
489
serviceIndexer := kubeInformerFactory .Core ().V1 ().Services ().Informer ().GetIndexer ()
488
- testutil .SetServices (serviceIndexer , tc .job , testutil .LabelWorker , tc .activeWorkerServices , t )
489
490
testutil .SetServices (serviceIndexer , tc .job , testutil .LabelMaster , tc .activeMasterServices , t )
490
491
491
492
ttl := tc .job .Spec .TTLSecondsAfterFinished
@@ -523,10 +524,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
523
524
succeededMasterPods int32
524
525
failedMasterPods int32
525
526
526
- activeWorkerServices int32
527
+
527
528
activeMasterServices int32
528
529
529
530
expectedPodDeletions int
531
+ expectedServiceDeletions int
530
532
}
531
533
532
534
ads2 := int64 (2 )
@@ -546,10 +548,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
546
548
succeededMasterPods : 0 ,
547
549
failedMasterPods : 0 ,
548
550
549
- activeWorkerServices : 4 ,
551
+
550
552
activeMasterServices : 1 ,
551
553
552
554
expectedPodDeletions : 0 ,
555
+ expectedServiceDeletions : 0 ,
553
556
},
554
557
testCase {
555
558
description : "1 master and 4 workers running, ActiveDeadlineSeconds is 2" ,
@@ -565,10 +568,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
565
568
succeededMasterPods : 0 ,
566
569
failedMasterPods : 0 ,
567
570
568
- activeWorkerServices : 4 ,
571
+
569
572
activeMasterServices : 1 ,
570
573
571
574
expectedPodDeletions : 5 ,
575
+ expectedServiceDeletions : 1 ,
572
576
},
573
577
}
574
578
for _ , tc := range testCases {
@@ -625,7 +629,7 @@ func TestActiveDeadlineSeconds(t *testing.T) {
625
629
testutil .SetPodsStatuses (podIndexer , tc .job , testutil .LabelMaster , tc .pendingMasterPods , tc .activeMasterPods , tc .succeededMasterPods , tc .failedMasterPods , nil , t )
626
630
627
631
serviceIndexer := kubeInformerFactory .Core ().V1 ().Services ().Informer ().GetIndexer ()
628
- testutil . SetServices ( serviceIndexer , tc . job , testutil . LabelWorker , tc . activeWorkerServices , t )
632
+
629
633
testutil .SetServices (serviceIndexer , tc .job , testutil .LabelMaster , tc .activeMasterServices , t )
630
634
631
635
foo , _ := ctr .getPyTorchJobFromName ("default" , "test-pytorchjob" )
@@ -645,8 +649,8 @@ func TestActiveDeadlineSeconds(t *testing.T) {
645
649
if len (fakePodControl .DeletePodName ) != tc .expectedPodDeletions {
646
650
t .Errorf ("%s: unexpected number of pod deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakePodControl .DeletePodName ))
647
651
}
648
- if len (fakeServiceControl .DeleteServiceName ) != tc .expectedPodDeletions {
649
- t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakeServiceControl .DeleteServiceName ))
652
+ if len (fakeServiceControl .DeleteServiceName ) != tc .expectedServiceDeletions {
653
+ t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedServiceDeletions , len (fakeServiceControl .DeleteServiceName ))
650
654
}
651
655
}
652
656
}
@@ -668,10 +672,11 @@ func TestBackoffForOnFailure(t *testing.T) {
668
672
succeededMasterPods int32
669
673
failedMasterPods int32
670
674
671
- activeWorkerServices int32
675
+
672
676
activeMasterServices int32
673
677
674
678
expectedPodDeletions int
679
+ expectedServiceDeletions int
675
680
}
676
681
677
682
backoffLimit4 := int32 (4 )
@@ -693,10 +698,11 @@ func TestBackoffForOnFailure(t *testing.T) {
693
698
succeededMasterPods : 0 ,
694
699
failedMasterPods : 0 ,
695
700
696
- activeWorkerServices : 4 ,
701
+
697
702
activeMasterServices : 1 ,
698
703
699
704
expectedPodDeletions : 5 ,
705
+ expectedServiceDeletions : 1 ,
700
706
},
701
707
}
702
708
for _ , tc := range testCases {
@@ -753,7 +759,7 @@ func TestBackoffForOnFailure(t *testing.T) {
753
759
testutil .SetPodsStatuses (podIndexer , tc .job , testutil .LabelMaster , tc .pendingMasterPods , tc .activeMasterPods , tc .succeededMasterPods , tc .failedMasterPods , tc .restartCounts , t )
754
760
755
761
serviceIndexer := kubeInformerFactory .Core ().V1 ().Services ().Informer ().GetIndexer ()
756
- testutil . SetServices ( serviceIndexer , tc . job , testutil . LabelWorker , tc . activeWorkerServices , t )
762
+
757
763
testutil .SetServices (serviceIndexer , tc .job , testutil .LabelMaster , tc .activeMasterServices , t )
758
764
759
765
forget , err := ctr .syncPyTorchJob (testutil .GetKey (tc .job , t ))
@@ -766,8 +772,8 @@ func TestBackoffForOnFailure(t *testing.T) {
766
772
if len (fakePodControl .DeletePodName ) != tc .expectedPodDeletions {
767
773
t .Errorf ("%s: unexpected number of pod deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakePodControl .DeletePodName ))
768
774
}
769
- if len (fakeServiceControl .DeleteServiceName ) != tc .expectedPodDeletions {
770
- t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedPodDeletions , len (fakeServiceControl .DeleteServiceName ))
775
+ if len (fakeServiceControl .DeleteServiceName ) != tc .expectedServiceDeletions {
776
+ t .Errorf ("%s: unexpected number of service deletes. Expected %d, saw %d\n " , tc .description , tc .expectedServiceDeletions , len (fakeServiceControl .DeleteServiceName ))
771
777
}
772
778
}
773
779
}
0 commit comments