Skip to content

Commit

Permalink
Update UT & e2e cases.
Browse files Browse the repository at this point in the history
Signed-off-by: jiangkaihua <jiangkaihua1@huawei.com>
  • Loading branch information
jiangkaihua committed Dec 12, 2022
1 parent 49e8054 commit 77330a3
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 107 deletions.
50 changes: 30 additions & 20 deletions pkg/scheduler/actions/allocate/allocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ import (

"github.com/agiledragon/gomonkey/v2"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/record"
"volcano.sh/volcano/pkg/scheduler/plugins/gang"
"volcano.sh/volcano/pkg/scheduler/plugins/priority"

storagev1 "k8s.io/api/storage/v1"
schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
"volcano.sh/volcano/pkg/scheduler/framework"
"volcano.sh/volcano/pkg/scheduler/plugins/drf"
"volcano.sh/volcano/pkg/scheduler/plugins/gang"
"volcano.sh/volcano/pkg/scheduler/plugins/priority"
"volcano.sh/volcano/pkg/scheduler/plugins/proportion"
"volcano.sh/volcano/pkg/scheduler/util"
)
Expand Down Expand Up @@ -245,16 +246,19 @@ func TestAllocate(t *testing.T) {
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),
option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}
sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)

schedulerCache.Binder = binder
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

for _, node := range test.nodes {
schedulerCache.AddNode(node)
Expand Down Expand Up @@ -417,15 +421,21 @@ func TestAllocateWithDynamicPVC(t *testing.T) {
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: fakeVolumeBinder,
Recorder: record.NewFakeRecorder(100),

option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = fakeVolumeBinder
schedulerCache.Recorder = record.NewFakeRecorder(100)

schedulerCache.AddQueueV1beta1(queue)
schedulerCache.AddPodGroupV1beta1(pg)
for i, pod := range test.pods {
Expand Down
26 changes: 15 additions & 11 deletions pkg/scheduler/actions/preempt/preempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

schedulingv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
"volcano.sh/volcano/pkg/scheduler/framework"
Expand Down Expand Up @@ -287,18 +287,22 @@ func TestPreempt(t *testing.T) {
evictor := &util.FakeEvictor{
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,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
PriorityClasses: make(map[string]*schedulingv1.PriorityClass),

Recorder: record.NewFakeRecorder(100),
option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.Evictor = evictor
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

schedulerCache.PriorityClasses["high-priority"] = &schedulingv1.PriorityClass{
Value: 100000,
}
Expand Down
29 changes: 17 additions & 12 deletions pkg/scheduler/actions/reclaim/reclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
"k8s.io/client-go/tools/record"

schedulingv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
"volcano.sh/volcano/pkg/scheduler/framework"
Expand Down Expand Up @@ -121,18 +122,22 @@ func TestReclaim(t *testing.T) {
evictor := &util.FakeEvictor{
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,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
PriorityClasses: make(map[string]*schedulingv1.PriorityClass),

Recorder: record.NewFakeRecorder(100),

option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.Evictor = evictor
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

schedulerCache.PriorityClasses["high-priority"] = &schedulingv1.PriorityClass{
Value: 100000,
}
Expand Down
36 changes: 21 additions & 15 deletions pkg/scheduler/actions/shuffle/shuffle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@
package shuffle

import (
"github.com/golang/mock/gomock"
"testing"
"time"
mock_framework "volcano.sh/volcano/pkg/scheduler/framework/mock_gen"

"github.com/golang/mock/gomock"
v1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"

schedulingv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
"volcano.sh/volcano/pkg/scheduler/framework"
mock_framework "volcano.sh/volcano/pkg/scheduler/framework/mock_gen"
"volcano.sh/volcano/pkg/scheduler/util"
)

Expand All @@ -44,8 +46,8 @@ func TestShuffle(t *testing.T) {
ctl := gomock.NewController(t)
fakePlugin := mock_framework.NewMockPlugin(ctl)
fakePlugin.EXPECT().Name().AnyTimes().Return("fake")
fakePlugin.EXPECT().OnSessionOpen(gomock.Any()).Return()
fakePlugin.EXPECT().OnSessionClose(gomock.Any()).Return()
fakePlugin.EXPECT().OnSessionOpen(gomock.Any()).AnyTimes().Return()
fakePlugin.EXPECT().OnSessionClose(gomock.Any()).AnyTimes().Return()
fakePluginBuilder := func(arguments framework.Arguments) framework.Plugin {
return fakePlugin
}
Expand Down Expand Up @@ -135,18 +137,22 @@ func TestShuffle(t *testing.T) {
evictor := &util.FakeEvictor{
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,
Evictor: evictor,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
PriorityClasses: make(map[string]*schedulingv1.PriorityClass),

Recorder: record.NewFakeRecorder(100),

option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.Evictor = evictor
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

schedulerCache.PriorityClasses["high-priority"] = &schedulingv1.PriorityClass{
Value: highPriority,
}
Expand Down
24 changes: 15 additions & 9 deletions pkg/scheduler/plugins/binpack/binpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"k8s.io/client-go/tools/record"

schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
"volcano.sh/volcano/pkg/scheduler/framework"
Expand Down Expand Up @@ -235,16 +236,21 @@ func TestNode(t *testing.T) {
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),
option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/scheduler/plugins/drf/hdrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

schedulingv1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/actions/allocate"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/cache"
Expand Down Expand Up @@ -210,15 +211,21 @@ func TestHDRF(t *testing.T) {
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),

option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = record.NewFakeRecorder(100)

for _, node := range test.nodes {
schedulerCache.AddNode(node)
}
Expand Down
36 changes: 22 additions & 14 deletions pkg/scheduler/plugins/proportion/proportion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ limitations under the License.
package proportion

import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"io/ioutil"
"k8s.io/client-go/util/workqueue"
"net/http"
"reflect"
"strconv"
"strings"
"testing"
"time"
"volcano.sh/volcano/pkg/scheduler/actions/allocate"

"github.com/agiledragon/gomonkey/v2"
"github.com/prometheus/client_golang/prometheus/promhttp"
"io/ioutil"

apiv1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"

"net/http"

schedulingv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
"volcano.sh/volcano/cmd/scheduler/app/options"
"volcano.sh/volcano/pkg/kube"
"volcano.sh/volcano/pkg/scheduler/actions/allocate"
"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/cache"
"volcano.sh/volcano/pkg/scheduler/conf"
Expand Down Expand Up @@ -197,16 +200,21 @@ func TestProportion(t *testing.T) {
t.Logf("%s: [Event] %s", test.name, event)
}
}()
schedulerCache := &cache.SchedulerCache{
Nodes: make(map[string]*api.NodeInfo),
Jobs: make(map[api.JobID]*api.JobInfo),
PriorityClasses: make(map[string]*schedulingv1.PriorityClass),
Queues: make(map[api.QueueID]*api.QueueInfo),
Binder: binder,
StatusUpdater: &util.FakeStatusUpdater{},
VolumeBinder: &util.FakeVolumeBinder{},
Recorder: recorder,

option := options.NewServerOption()
option.RegisterOptions()
config, err := kube.BuildConfig(option.KubeClientOptions)
if err != nil {
return
}

sc := cache.New(config, option.SchedulerNames, option.DefaultQueue, option.NodeSelector)
schedulerCache := sc.(*cache.SchedulerCache)
schedulerCache.Binder = binder
schedulerCache.StatusUpdater = &util.FakeStatusUpdater{}
schedulerCache.VolumeBinder = &util.FakeVolumeBinder{}
schedulerCache.Recorder = recorder

// deletedJobs to DeletedJobs
schedulerCache.DeletedJobs = workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())

Expand Down
Loading

0 comments on commit 77330a3

Please sign in to comment.