Skip to content

Commit 22ea5ea

Browse files
committed
fix(job_test) test case should not include worker service
1 parent 5522f91 commit 22ea5ea

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

pkg/controller.v1/pytorch/job_test.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func TestDeletePodsAndServices(t *testing.T) {
214214
activeMasterServices int32
215215

216216
expectedPodDeletions int
217+
expectedServiceDeletions int
217218
}
218219

219220
testCases := []testCase{
@@ -235,6 +236,7 @@ func TestDeletePodsAndServices(t *testing.T) {
235236
activeMasterServices: 1,
236237

237238
expectedPodDeletions: 5,
239+
expectedServiceDeletions: 1,
238240
},
239241
testCase{
240242
description: "4 workers and 1 master succeeded, policy is None",
@@ -254,6 +256,7 @@ func TestDeletePodsAndServices(t *testing.T) {
254256
activeMasterServices: 1,
255257

256258
expectedPodDeletions: 0,
259+
expectedServiceDeletions: 0,
257260
},
258261
}
259262
for _, tc := range testCases {
@@ -315,7 +318,6 @@ func TestDeletePodsAndServices(t *testing.T) {
315318
testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t)
316319

317320
serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer()
318-
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t)
319321
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t)
320322

321323
forget, err := ctr.syncPyTorchJob(testutil.GetKey(tc.job, t))
@@ -329,8 +331,8 @@ func TestDeletePodsAndServices(t *testing.T) {
329331
if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions {
330332
t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName))
331333
}
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))
334336
}
335337
}
336338
}
@@ -413,7 +415,7 @@ func TestCleanupPyTorchJob(t *testing.T) {
413415
succeededMasterPods: 1,
414416
failedMasterPods: 0,
415417

416-
activeWorkerServices: 4,
418+
417419
activeMasterServices: 1,
418420

419421
expectedDeleteFinished: true,
@@ -485,7 +487,6 @@ func TestCleanupPyTorchJob(t *testing.T) {
485487
testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t)
486488

487489
serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer()
488-
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t)
489490
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t)
490491

491492
ttl := tc.job.Spec.TTLSecondsAfterFinished
@@ -523,10 +524,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
523524
succeededMasterPods int32
524525
failedMasterPods int32
525526

526-
activeWorkerServices int32
527+
527528
activeMasterServices int32
528529

529530
expectedPodDeletions int
531+
expectedServiceDeletions int
530532
}
531533

532534
ads2 := int64(2)
@@ -546,10 +548,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
546548
succeededMasterPods: 0,
547549
failedMasterPods: 0,
548550

549-
activeWorkerServices: 4,
551+
550552
activeMasterServices: 1,
551553

552554
expectedPodDeletions: 0,
555+
expectedServiceDeletions: 0,
553556
},
554557
testCase{
555558
description: "1 master and 4 workers running, ActiveDeadlineSeconds is 2",
@@ -565,10 +568,11 @@ func TestActiveDeadlineSeconds(t *testing.T) {
565568
succeededMasterPods: 0,
566569
failedMasterPods: 0,
567570

568-
activeWorkerServices: 4,
571+
569572
activeMasterServices: 1,
570573

571574
expectedPodDeletions: 5,
575+
expectedServiceDeletions: 1,
572576
},
573577
}
574578
for _, tc := range testCases {
@@ -625,7 +629,7 @@ func TestActiveDeadlineSeconds(t *testing.T) {
625629
testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t)
626630

627631
serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer()
628-
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t)
632+
629633
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t)
630634

631635
foo, _ := ctr.getPyTorchJobFromName("default", "test-pytorchjob")
@@ -645,8 +649,8 @@ func TestActiveDeadlineSeconds(t *testing.T) {
645649
if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions {
646650
t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName))
647651
}
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))
650654
}
651655
}
652656
}
@@ -668,10 +672,11 @@ func TestBackoffForOnFailure(t *testing.T) {
668672
succeededMasterPods int32
669673
failedMasterPods int32
670674

671-
activeWorkerServices int32
675+
672676
activeMasterServices int32
673677

674678
expectedPodDeletions int
679+
expectedServiceDeletions int
675680
}
676681

677682
backoffLimit4 := int32(4)
@@ -693,10 +698,11 @@ func TestBackoffForOnFailure(t *testing.T) {
693698
succeededMasterPods: 0,
694699
failedMasterPods: 0,
695700

696-
activeWorkerServices: 4,
701+
697702
activeMasterServices: 1,
698703

699704
expectedPodDeletions: 5,
705+
expectedServiceDeletions: 1,
700706
},
701707
}
702708
for _, tc := range testCases {
@@ -753,7 +759,7 @@ func TestBackoffForOnFailure(t *testing.T) {
753759
testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, tc.restartCounts, t)
754760

755761
serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer()
756-
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t)
762+
757763
testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t)
758764

759765
forget, err := ctr.syncPyTorchJob(testutil.GetKey(tc.job, t))
@@ -766,8 +772,8 @@ func TestBackoffForOnFailure(t *testing.T) {
766772
if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions {
767773
t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName))
768774
}
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))
771777
}
772778
}
773779
}

vendor/github.com/kubeflow/tf-operator/pkg/control/service_control.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)