From 99c14e05769fe3ddcfb7ed71461015c159eb4ec2 Mon Sep 17 00:00:00 2001 From: lianjun-zhang Date: Tue, 11 Jun 2024 09:31:54 +0800 Subject: [PATCH] hccl clean code --- pkg/ring-controller/agent/vcjobworker.go | 7 ++++++- pkg/ring-controller/agent/vcjobworker_test.go | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/ring-controller/agent/vcjobworker.go b/pkg/ring-controller/agent/vcjobworker.go index a6d5d6d..b331a58 100644 --- a/pkg/ring-controller/agent/vcjobworker.go +++ b/pkg/ring-controller/agent/vcjobworker.go @@ -191,7 +191,12 @@ func (b *VCJobWorker) cacheReadyPods(pods []*apiCoreV1.Pod) error { var err error errs.Range(func(key, value interface{}) bool { if value != nil { - err = value.(error) + errVal, ok := value.(error) + if !ok { + hwlog.RunLog.Errorf("failed to convert") + return false + } + err = errVal return false } return true diff --git a/pkg/ring-controller/agent/vcjobworker_test.go b/pkg/ring-controller/agent/vcjobworker_test.go index f3f0258..66f5058 100644 --- a/pkg/ring-controller/agent/vcjobworker_test.go +++ b/pkg/ring-controller/agent/vcjobworker_test.go @@ -19,12 +19,13 @@ import ( "encoding/json" "errors" "fmt" - "k8s.io/client-go/kubernetes" "reflect" "sync" "testing" "time" + "k8s.io/client-go/kubernetes" + "github.com/agiledragon/gomonkey/v2" "github.com/smartystreets/goconvey/convey" corev1 "k8s.io/api/core/v1" @@ -214,8 +215,8 @@ func TestValidateRank(t *testing.T) { }) } -func TestGetOrSetPodIndex(t *testing.T) { - convey.Convey("test getOrSetPodIndex", t, func() { +func TestGetPodIndex(t *testing.T) { + convey.Convey("test get PodIndex", t, func() { worker := &WorkerInfo{ cachedIndex: &sync.Map{}, taskReplicasTotal: 2, @@ -256,6 +257,16 @@ func TestGetOrSetPodIndex(t *testing.T) { convey.ShouldEqual(rank, 0) convey.ShouldBeNil(err) }) + }) + +} + +func TestGetOrSetPodIndex(t *testing.T) { + convey.Convey("test getOrSetPodIndex", t, func() { + worker := &WorkerInfo{ + cachedIndex: &sync.Map{}, + taskReplicasTotal: 2, + } convey.Convey("pod without rankIndex will return normal rank and nil", func() { pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ -- Gitee