Skip to content

Commit

Permalink
test: add some ut test in plugins numaaware policy
Browse files Browse the repository at this point in the history
Signed-off-by: googs1025 <[email protected]>
  • Loading branch information
googs1025 committed Apr 11, 2024
1 parent 0c71d86 commit 408b02c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/scheduler/actions/preempt/preempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestPreempt(t *testing.T) {
test.Plugins = plugins
test.PriClass = []*schedulingv1.PriorityClass{highPrio, lowPrio}
t.Run(test.Name, func(t *testing.T) {
test.RegistSession(tiers, nil)
test.RegisterSession(tiers, nil)
defer test.Close()
test.Run(actions)
if err := test.CheckAll(i); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/drf/hdrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestHDRF(t *testing.T) {
}
for _, test := range tests {
t.Run(t.Name(), func(t *testing.T) {
ssn := test.RegistSession(tiers, nil)
ssn := test.RegisterSession(tiers, nil)
defer test.Close()
test.Run([]framework.Action{allocate.New()})
for _, job := range ssn.Jobs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func Test_best_effort_predicate(t *testing.T) {
teseCases := []struct {
testCases := []struct {
name string
providersHints []map[string][]TopologyHint
expect TopologyHint
Expand Down Expand Up @@ -312,7 +312,7 @@ func Test_best_effort_predicate(t *testing.T) {
},
}

for _, testcase := range teseCases {
for _, testcase := range testCases {
policy := NewPolicyBestEffort([]int{0, 1})
bestHit, _ := policy.Predicate(testcase.providersHints)
if !reflect.DeepEqual(bestHit, testcase.expect) {
Expand Down
44 changes: 44 additions & 0 deletions pkg/scheduler/plugins/numaaware/policy/policy_none_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2021 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package policy

import (
"reflect"
"testing"
)

func Test_none_predicate(t *testing.T) {
testCases := []struct {
name string
providersHints []map[string][]TopologyHint
expect TopologyHint
}{
{
name: "test-1",
providersHints: []map[string][]TopologyHint{},
expect: TopologyHint{},
},
}

for _, testcase := range testCases {
policy := NewPolicyNone([]int{0, 1})
bestHit, _ := policy.Predicate(testcase.providersHints)
if !reflect.DeepEqual(bestHit, testcase.expect) {
t.Errorf("%s failed, expect %v, bestHit= %v\n", testcase.name, testcase.expect, bestHit)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func Test_restricted_predicate(t *testing.T) {
teseCases := []struct {
testCases := []struct {
name string
providersHints []map[string][]TopologyHint
expect TopologyHint
Expand Down Expand Up @@ -312,7 +312,7 @@ func Test_restricted_predicate(t *testing.T) {
},
}

for _, testcase := range teseCases {
for _, testcase := range testCases {
policy := NewPolicyRestricted([]int{0, 1})
bestHit, _ := policy.Predicate(testcase.providersHints)
if !reflect.DeepEqual(bestHit, testcase.expect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func Test_single_numa_node_predicate(t *testing.T) {
teseCases := []struct {
testCases := []struct {
name string
providersHints []map[string][]TopologyHint
expect TopologyHint
Expand Down Expand Up @@ -278,7 +278,7 @@ func Test_single_numa_node_predicate(t *testing.T) {
},
}

for _, testcase := range teseCases {
for _, testcase := range testCases {
policy := NewPolicySingleNumaNode([]int{0, 1})
bestHit, _ := policy.Predicate(testcase.providersHints)
if !reflect.DeepEqual(bestHit, testcase.expect) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/predicates/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestEventHandler(t *testing.T) {
},
}
t.Run(test.Name, func(t *testing.T) {
test.RegistSession(tiers, nil)
test.RegisterSession(tiers, nil)
defer test.Close()
test.Run(actions)
if err := test.CheckAll(i); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/scheduler/uthelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"volcano.sh/volcano/pkg/scheduler/util"
)

// RegistPlugins plugins
func RegistPlugins(plugins map[string]framework.PluginBuilder) {
// RegisterPlugins plugins
func RegisterPlugins(plugins map[string]framework.PluginBuilder) {
for name, plugin := range plugins {
framework.RegisterPluginBuilder(name, plugin)
}
Expand Down Expand Up @@ -68,8 +68,8 @@ type TestCommonStruct struct {

var _ Interface = &TestCommonStruct{}

// RegistSession open session with tiers and configuration, and mock schedulerCache with self-defined FakeBinder and FakeEvictor
func (test *TestCommonStruct) RegistSession(tiers []conf.Tier, config []conf.Configuration) *framework.Session {
// RegisterSession open session with tiers and configuration, and mock schedulerCache with self-defined FakeBinder and FakeEvictor
func (test *TestCommonStruct) RegisterSession(tiers []conf.Tier, config []conf.Configuration) *framework.Session {
binder := &util.FakeBinder{
Binds: map[string]string{},
Channel: make(chan string),
Expand Down Expand Up @@ -102,7 +102,7 @@ func (test *TestCommonStruct) RegistSession(tiers []conf.Tier, config []conf.Con
schedulerCache.AddPriorityClass(pc)
}

RegistPlugins(test.Plugins)
RegisterPlugins(test.Plugins)
ssn := framework.OpenSession(schedulerCache, tiers, config)
test.ssn = ssn
schedulerCache.Run(test.stop)
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/uthelper/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
type Interface interface {
// Run executes the actions
Run(actions []framework.Action)
// RegistSession init the session
RegistSession(tiers []conf.Tier, config []conf.Configuration) *framework.Session
// RegisterSession init the session
RegisterSession(tiers []conf.Tier, config []conf.Configuration) *framework.Session
// Close release session and do cleanup
Close()
// CheckAll do all checks
Expand Down

0 comments on commit 408b02c

Please sign in to comment.