Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add some ut test in plugins numaaware policy #3400

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/scheduler/actions/allocate/allocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestAllocate(t *testing.T) {
for i, test := range tests {
t.Run(test.Name, func(t *testing.T) {
test.Plugins = plugins
test.RegistSession(tiers, nil)
test.RegisterSession(tiers, nil)
defer test.Close()
test.Run([]framework.Action{New()})
if err := test.CheckAll(i); err != nil {
Expand Down
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/actions/reclaim/reclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestReclaim(t *testing.T) {
},
}
test.Plugins = plugins
test.RegistSession(tiers, nil)
test.RegisterSession(tiers, nil)
test.Run([]framework.Action{reclaim})
if err := test.CheckAll(i); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/actions/shuffle/shuffle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestShuffle(t *testing.T) {
}

t.Run(test.Name, func(t *testing.T) {
ssn := test.RegistSession(tiers, nil)
ssn := test.RegisterSession(tiers, nil)
defer test.Close()
ssn.AddVictimTasksFns("fake", fakePluginVictimFns())
test.Run([]framework.Action{shuffle})
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/binpack/binpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestNode(t *testing.T) {
},
},
}
ssn := test.RegistSession(tiers, nil)
ssn := test.RegisterSession(tiers, nil)
for _, job := range ssn.Jobs {
for _, task := range job.Tasks {
taskID := fmt.Sprintf("%s/%s", task.Namespace, task.Name)
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 2024 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
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/tdm/tdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func Test_TDM(t *testing.T) {
},
},
}
ssn := test.RegistSession(tiers, nil)
ssn := test.RegisterSession(tiers, nil)
defer test.Close()

for _, job := range ssn.Jobs {
Expand Down Expand Up @@ -541,7 +541,7 @@ func Test_TDM_victimsFn(t *testing.T) {
},
},
}
ssn := test.RegistSession(tiers, nil)
ssn := test.RegisterSession(tiers, nil)
defer test.Close()

d, _ := time.ParseDuration(test.args[evictPeriodLabel].(string))
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
Loading