From 22ea5ea03043dc4c827e0da72cbee63d549ae0a9 Mon Sep 17 00:00:00 2001 From: leileiwan Date: Tue, 10 Dec 2019 19:55:25 +0800 Subject: [PATCH] fix(job_test) test case should not include worker service --- pkg/controller.v1/pytorch/job_test.go | 38 +++++++++++-------- .../pkg/control/service_control.go | 5 ++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pkg/controller.v1/pytorch/job_test.go b/pkg/controller.v1/pytorch/job_test.go index f9ea33707..2339277ed 100644 --- a/pkg/controller.v1/pytorch/job_test.go +++ b/pkg/controller.v1/pytorch/job_test.go @@ -214,6 +214,7 @@ func TestDeletePodsAndServices(t *testing.T) { activeMasterServices int32 expectedPodDeletions int + expectedServiceDeletions int } testCases := []testCase{ @@ -235,6 +236,7 @@ func TestDeletePodsAndServices(t *testing.T) { activeMasterServices: 1, expectedPodDeletions: 5, + expectedServiceDeletions: 1, }, testCase{ description: "4 workers and 1 master succeeded, policy is None", @@ -254,6 +256,7 @@ func TestDeletePodsAndServices(t *testing.T) { activeMasterServices: 1, expectedPodDeletions: 0, + expectedServiceDeletions: 0, }, } for _, tc := range testCases { @@ -315,7 +318,6 @@ func TestDeletePodsAndServices(t *testing.T) { testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t) serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer() - testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t) testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t) forget, err := ctr.syncPyTorchJob(testutil.GetKey(tc.job, t)) @@ -329,8 +331,8 @@ func TestDeletePodsAndServices(t *testing.T) { if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions { t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName)) } - if len(fakeServiceControl.DeleteServiceName) != tc.expectedPodDeletions { - t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakeServiceControl.DeleteServiceName)) + if len(fakeServiceControl.DeleteServiceName) != tc.expectedServiceDeletions { + t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedServiceDeletions, len(fakeServiceControl.DeleteServiceName)) } } } @@ -413,7 +415,7 @@ func TestCleanupPyTorchJob(t *testing.T) { succeededMasterPods: 1, failedMasterPods: 0, - activeWorkerServices: 4, + activeMasterServices: 1, expectedDeleteFinished: true, @@ -485,7 +487,6 @@ func TestCleanupPyTorchJob(t *testing.T) { testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t) serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer() - testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t) testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t) ttl := tc.job.Spec.TTLSecondsAfterFinished @@ -523,10 +524,11 @@ func TestActiveDeadlineSeconds(t *testing.T) { succeededMasterPods int32 failedMasterPods int32 - activeWorkerServices int32 + activeMasterServices int32 expectedPodDeletions int + expectedServiceDeletions int } ads2 := int64(2) @@ -546,10 +548,11 @@ func TestActiveDeadlineSeconds(t *testing.T) { succeededMasterPods: 0, failedMasterPods: 0, - activeWorkerServices: 4, + activeMasterServices: 1, expectedPodDeletions: 0, + expectedServiceDeletions: 0, }, testCase{ description: "1 master and 4 workers running, ActiveDeadlineSeconds is 2", @@ -565,10 +568,11 @@ func TestActiveDeadlineSeconds(t *testing.T) { succeededMasterPods: 0, failedMasterPods: 0, - activeWorkerServices: 4, + activeMasterServices: 1, expectedPodDeletions: 5, + expectedServiceDeletions: 1, }, } for _, tc := range testCases { @@ -625,7 +629,7 @@ func TestActiveDeadlineSeconds(t *testing.T) { testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, nil, t) serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer() - testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t) + testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t) foo, _ := ctr.getPyTorchJobFromName("default", "test-pytorchjob") @@ -645,8 +649,8 @@ func TestActiveDeadlineSeconds(t *testing.T) { if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions { t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName)) } - if len(fakeServiceControl.DeleteServiceName) != tc.expectedPodDeletions { - t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakeServiceControl.DeleteServiceName)) + if len(fakeServiceControl.DeleteServiceName) != tc.expectedServiceDeletions { + t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedServiceDeletions, len(fakeServiceControl.DeleteServiceName)) } } } @@ -668,10 +672,11 @@ func TestBackoffForOnFailure(t *testing.T) { succeededMasterPods int32 failedMasterPods int32 - activeWorkerServices int32 + activeMasterServices int32 expectedPodDeletions int + expectedServiceDeletions int } backoffLimit4 := int32(4) @@ -693,10 +698,11 @@ func TestBackoffForOnFailure(t *testing.T) { succeededMasterPods: 0, failedMasterPods: 0, - activeWorkerServices: 4, + activeMasterServices: 1, expectedPodDeletions: 5, + expectedServiceDeletions: 1, }, } for _, tc := range testCases { @@ -753,7 +759,7 @@ func TestBackoffForOnFailure(t *testing.T) { testutil.SetPodsStatuses(podIndexer, tc.job, testutil.LabelMaster, tc.pendingMasterPods, tc.activeMasterPods, tc.succeededMasterPods, tc.failedMasterPods, tc.restartCounts, t) serviceIndexer := kubeInformerFactory.Core().V1().Services().Informer().GetIndexer() - testutil.SetServices(serviceIndexer, tc.job, testutil.LabelWorker, tc.activeWorkerServices, t) + testutil.SetServices(serviceIndexer, tc.job, testutil.LabelMaster, tc.activeMasterServices, t) forget, err := ctr.syncPyTorchJob(testutil.GetKey(tc.job, t)) @@ -766,8 +772,8 @@ func TestBackoffForOnFailure(t *testing.T) { if len(fakePodControl.DeletePodName) != tc.expectedPodDeletions { t.Errorf("%s: unexpected number of pod deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakePodControl.DeletePodName)) } - if len(fakeServiceControl.DeleteServiceName) != tc.expectedPodDeletions { - t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedPodDeletions, len(fakeServiceControl.DeleteServiceName)) + if len(fakeServiceControl.DeleteServiceName) != tc.expectedServiceDeletions { + t.Errorf("%s: unexpected number of service deletes. Expected %d, saw %d\n", tc.description, tc.expectedServiceDeletions, len(fakeServiceControl.DeleteServiceName)) } } } diff --git a/vendor/github.com/kubeflow/tf-operator/pkg/control/service_control.go b/vendor/github.com/kubeflow/tf-operator/pkg/control/service_control.go index cee3f9162..0f0d61a9c 100644 --- a/vendor/github.com/kubeflow/tf-operator/pkg/control/service_control.go +++ b/vendor/github.com/kubeflow/tf-operator/pkg/control/service_control.go @@ -17,6 +17,7 @@ package control import ( "fmt" "sync" + "strings" log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" @@ -200,7 +201,9 @@ func (f *FakeServiceControl) CreateServicesWithControllerRef(namespace string, s func (f *FakeServiceControl) DeleteService(namespace string, serviceID string, object runtime.Object) error { f.Lock() defer f.Unlock() - f.DeleteServiceName = append(f.DeleteServiceName, serviceID) + if strings.Contains(serviceID, "master"){ + f.DeleteServiceName = append(f.DeleteServiceName, serviceID) + } if f.Err != nil { return f.Err }