Skip to content

Commit

Permalink
add UT for shuffle action and mock a plugin with golang mock
Browse files Browse the repository at this point in the history
Signed-off-by: Thor-wl <13164644535@163.com>
  • Loading branch information
Thor-wl committed Apr 24, 2022
1 parent 1eb451d commit b7138dd
Show file tree
Hide file tree
Showing 13 changed files with 1,666 additions and 61 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
github.com/agiledragon/gomonkey/v2 v2.1.0
github.com/fsnotify/fsnotify v1.4.9
github.com/golang/mock v1.6.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/go-multierror v1.0.0
github.com/imdario/mergo v0.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
59 changes: 0 additions & 59 deletions pkg/scheduler/actions/shuffle/fake_plugin.go

This file was deleted.

30 changes: 28 additions & 2 deletions pkg/scheduler/actions/shuffle/shuffle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package shuffle

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

v1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
Expand All @@ -39,7 +41,15 @@ func TestShuffle(t *testing.T) {
highPriority = 100
lowPriority = 10

framework.RegisterPluginBuilder("fake", NewFakePlugin)
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()
fakePluginBuilder := func(arguments framework.Arguments) framework.Plugin {
return fakePlugin
}
framework.RegisterPluginBuilder("fake", fakePluginBuilder)

tests := []struct {
name string
Expand Down Expand Up @@ -170,8 +180,24 @@ func TestShuffle(t *testing.T) {
}, nil)
defer framework.CloseSession(ssn)

shuffle.Execute(ssn)
fakePluginVictimFns := func() []api.VictimTasksFn {
victimTasksFn := func(candidates []*api.TaskInfo) []*api.TaskInfo {
evicts := make([]*api.TaskInfo, 0)
for _, task := range candidates {
if task.Priority == lowPriority {
evicts = append(evicts, task)
}
}
return evicts
}

victimTasksFns := make([]api.VictimTasksFn, 0)
victimTasksFns = append(victimTasksFns, victimTasksFn)
return victimTasksFns
}
ssn.AddVictimTasksFns("fake", fakePluginVictimFns())

shuffle.Execute(ssn)
for {
select {
case <-evictor.Channel:
Expand Down
146 changes: 146 additions & 0 deletions pkg/scheduler/framework/mock_gen/action_and_plugin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/golang/mock/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions vendor/github.com/golang/mock/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b7138dd

Please sign in to comment.