From 816169463b9b93a88224ac5185eceb9c541942c5 Mon Sep 17 00:00:00 2001 From: xuzhonghu Date: Sat, 20 Jul 2019 18:54:55 +0800 Subject: [PATCH] ut --- .../actions/allocate/allocate_test.go | 114 +++++++++--------- pkg/scheduler/actions/preempt/preempt_test.go | 4 +- pkg/scheduler/actions/reclaim/reclaim_test.go | 4 +- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/pkg/scheduler/actions/allocate/allocate_test.go b/pkg/scheduler/actions/allocate/allocate_test.go index d1834afb238..7b2a50cf4fe 100644 --- a/pkg/scheduler/actions/allocate/allocate_test.go +++ b/pkg/scheduler/actions/allocate/allocate_test.go @@ -146,67 +146,69 @@ func TestAllocate(t *testing.T) { allocate := New() - for i, test := range tests { - binder := &util.FakeBinder{ - Binds: map[string]string{}, - Channel: make(chan string), - } - schedulerCache := &cache.SchedulerCache{ - Nodes: make(map[string]*api.NodeInfo), - Jobs: make(map[api.JobID]*api.JobInfo), - Queues: make(map[api.QueueID]*api.QueueInfo), - Binder: binder, - StatusUpdater: &util.FakeStatusUpdater{}, - VolumeBinder: &util.FakeVolumeBinder{}, - - Recorder: record.NewFakeRecorder(100), - } - for _, node := range test.nodes { - schedulerCache.AddNode(node) - } - for _, pod := range test.pods { - schedulerCache.AddPod(pod) - } - - for _, ss := range test.podGroups { - schedulerCache.AddPodGroupV1alpha1(ss) - } - - for _, q := range test.queues { - schedulerCache.AddQueueV1alpha1(q) - } - - trueValue := true - ssn := framework.OpenSession(schedulerCache, []conf.Tier{ - { - Plugins: []conf.PluginOption{ - { - Name: "drf", - EnabledPreemptable: &trueValue, - EnabledJobOrder: &trueValue, - }, - { - Name: "proportion", - EnabledQueueOrder: &trueValue, - EnabledReclaimable: &trueValue, + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + binder := &util.FakeBinder{ + Binds: map[string]string{}, + Channel: make(chan string), + } + schedulerCache := &cache.SchedulerCache{ + Nodes: make(map[string]*api.NodeInfo), + Jobs: make(map[api.JobID]*api.JobInfo), + Queues: make(map[api.QueueID]*api.QueueInfo), + Binder: binder, + StatusUpdater: &util.FakeStatusUpdater{}, + VolumeBinder: &util.FakeVolumeBinder{}, + + Recorder: record.NewFakeRecorder(100), + } + for _, node := range test.nodes { + schedulerCache.AddNode(node) + } + for _, pod := range test.pods { + schedulerCache.AddPod(pod) + } + + for _, ss := range test.podGroups { + schedulerCache.AddPodGroupV1alpha2(ss) + } + + for _, q := range test.queues { + schedulerCache.AddQueueV1alpha2(q) + } + + trueValue := true + ssn := framework.OpenSession(schedulerCache, []conf.Tier{ + { + Plugins: []conf.PluginOption{ + { + Name: "drf", + EnabledPreemptable: &trueValue, + EnabledJobOrder: &trueValue, + }, + { + Name: "proportion", + EnabledQueueOrder: &trueValue, + EnabledReclaimable: &trueValue, + }, }, }, - }, - }) - defer framework.CloseSession(ssn) + }) + defer framework.CloseSession(ssn) - allocate.Execute(ssn) + allocate.Execute(ssn) - for i := 0; i < len(test.expected); i++ { - select { - case <-binder.Channel: - case <-time.After(3 * time.Second): - t.Errorf("Failed to get binding request.") + for i := 0; i < len(test.expected); i++ { + select { + case <-binder.Channel: + case <-time.After(3 * time.Second): + t.Errorf("Failed to get binding request.") + } } - } - if !reflect.DeepEqual(test.expected, binder.Binds) { - t.Errorf("case %d (%s): expected: %v, got %v ", i, test.name, test.expected, binder.Binds) - } + if !reflect.DeepEqual(test.expected, binder.Binds) { + t.Errorf("expected: %v, got %v ", test.expected, binder.Binds) + } + }) } } diff --git a/pkg/scheduler/actions/preempt/preempt_test.go b/pkg/scheduler/actions/preempt/preempt_test.go index d2631e85bc7..87970fbb1c9 100644 --- a/pkg/scheduler/actions/preempt/preempt_test.go +++ b/pkg/scheduler/actions/preempt/preempt_test.go @@ -161,11 +161,11 @@ func TestPreempt(t *testing.T) { } for _, ss := range test.podGroups { - schedulerCache.AddPodGroupV1alpha1(ss) + schedulerCache.AddPodGroupV1alpha2(ss) } for _, q := range test.queues { - schedulerCache.AddQueueV1alpha1(q) + schedulerCache.AddQueueV1alpha2(q) } trueValue := true diff --git a/pkg/scheduler/actions/reclaim/reclaim_test.go b/pkg/scheduler/actions/reclaim/reclaim_test.go index 124fef99bf6..b957e39598e 100644 --- a/pkg/scheduler/actions/reclaim/reclaim_test.go +++ b/pkg/scheduler/actions/reclaim/reclaim_test.go @@ -130,11 +130,11 @@ func TestReclaim(t *testing.T) { } for _, ss := range test.podGroups { - schedulerCache.AddPodGroupV1alpha1(ss) + schedulerCache.AddPodGroupV1alpha2(ss) } for _, q := range test.queues { - schedulerCache.AddQueueV1alpha1(q) + schedulerCache.AddQueueV1alpha2(q) } trueValue := true