Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Fix Unit Tests #293

Merged
merged 4 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/controller.v1/pytorch/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package pytorch

import (
"fmt"
"time"
"strings"
"time"

log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
Expand All @@ -12,8 +12,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"

pyv1 "github.com/kubeflow/pytorch-operator/pkg/apis/pytorch/v1"
common "github.com/kubeflow/common/job_controller/api/v1"
pyv1 "github.com/kubeflow/pytorch-operator/pkg/apis/pytorch/v1"
pylogger "github.com/kubeflow/tf-operator/pkg/logger"
"github.com/kubeflow/tf-operator/pkg/util/k8sutil"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -150,7 +150,7 @@ func (pc *PyTorchController) updatePyTorchJob(old, cur interface{}) {
}

// deletePodsAndServices deletes all the pods and master service.
func (pc *PyTorchController) deletePodsAndServices(job *pyv1.PyTorchJob, pods []*v1.Pod,services []*v1.Service) error {
func (pc *PyTorchController) deletePodsAndServices(job *pyv1.PyTorchJob, pods []*v1.Pod, services []*v1.Service) error {
if len(pods) == 0 {
return nil
}
Expand All @@ -175,7 +175,7 @@ func (pc *PyTorchController) deletePodsAndServices(job *pyv1.PyTorchJob, pods []
if err != nil {
return err
}
for _,service :=range services{
for _, service := range services {
if err := pc.ServiceControl.DeleteService(service.Namespace, service.Name, job); err != nil {
return err
}
Expand Down
18 changes: 12 additions & 6 deletions pkg/controller.v1/pytorch/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ func TestCopyLabelsAndAnnotation(t *testing.T) {
jobIndexer := ctr.jobInformer.GetIndexer()

stopCh := make(chan struct{})
run := func(<-chan struct{}) {
if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil {
t.Errorf("Failed to run the controller: %v", err)
}

go func() {
// It is a hack to let the controller stop to run without errors.
// We can not just send a struct to stopCh because there are multiple
// receivers in controller.Run.
time.Sleep(testutil.SleepInterval)
stopCh <- struct{}{}
}()
err := ctr.Run(testutil.ThreadCount, stopCh)
if err != nil {
t.Errorf("Failed to run the controller: %v", err)
}
go run(stopCh)

ctr.updateStatusHandler = func(job *pyv1.PyTorchJob) error {
return nil
Expand Down Expand Up @@ -276,7 +282,7 @@ func TestDeletePodsAndServices(t *testing.T) {
activeMasterServices: 1,

expectedPodDeletions: 0,
expectedServiceDeletions: 0,
expectedServiceDeletions: 1,
},
testCase{
description: "4 workers and 1 master succeeded, policy is None",
Expand Down
18 changes: 12 additions & 6 deletions pkg/controller.v1/pytorch/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ package pytorch

import (
"testing"
"time"

kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned"
v1 "k8s.io/api/core/v1"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/controller"

common "github.com/kubeflow/common/job_controller/api/v1"
"github.com/kubeflow/pytorch-operator/cmd/pytorch-operator.v1/app/options"
pyv1 "github.com/kubeflow/pytorch-operator/pkg/apis/pytorch/v1"
jobclientset "github.com/kubeflow/pytorch-operator/pkg/client/clientset/versioned"
"github.com/kubeflow/pytorch-operator/pkg/common/util/v1/testutil"
common "github.com/kubeflow/common/job_controller/api/v1"
)

func TestAddPod(t *testing.T) {
Expand Down Expand Up @@ -258,12 +259,17 @@ func TestExitCode(t *testing.T) {
podIndexer := kubeInformerFactory.Core().V1().Pods().Informer().GetIndexer()

stopCh := make(chan struct{})
run := func(<-chan struct{}) {
if err := ctr.Run(testutil.ThreadCount, stopCh); err != nil {
t.Errorf("Failed to run the controller: %v", err)
}
go func() {
// It is a hack to let the controller stop to run without errors.
// We can not just send a struct to stopCh because there are multiple
// receivers in controller.Run.
time.Sleep(testutil.SleepInterval)
stopCh <- struct{}{}
}()
err := ctr.Run(testutil.ThreadCount, stopCh)
if err != nil {
t.Errorf("Failed to run the controller: %v", err)
}
go run(stopCh)

ctr.updateStatusHandler = func(job *pyv1.PyTorchJob) error {
return nil
Expand Down