From 408b02ca7b940d82b38d9370b8158067c193fa86 Mon Sep 17 00:00:00 2001 From: googs1025 Date: Thu, 11 Apr 2024 09:01:19 +0800 Subject: [PATCH] test: add some ut test in plugins numaaware policy Signed-off-by: googs1025 --- pkg/scheduler/actions/preempt/preempt_test.go | 2 +- pkg/scheduler/plugins/drf/hdrf_test.go | 2 +- .../policy/policy_best_effort_test.go | 4 +- .../numaaware/policy/policy_none_test.go | 44 +++++++++++++++++++ .../policy/policy_restricted_test.go | 4 +- .../policy/policy_single_numa_node_test.go | 4 +- .../plugins/predicates/predicates_test.go | 2 +- pkg/scheduler/uthelper/helper.go | 10 ++--- pkg/scheduler/uthelper/interface.go | 4 +- 9 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 pkg/scheduler/plugins/numaaware/policy/policy_none_test.go diff --git a/pkg/scheduler/actions/preempt/preempt_test.go b/pkg/scheduler/actions/preempt/preempt_test.go index 72a9df95ad..3421f243cf 100644 --- a/pkg/scheduler/actions/preempt/preempt_test.go +++ b/pkg/scheduler/actions/preempt/preempt_test.go @@ -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 { diff --git a/pkg/scheduler/plugins/drf/hdrf_test.go b/pkg/scheduler/plugins/drf/hdrf_test.go index 7e57550038..69b481f018 100644 --- a/pkg/scheduler/plugins/drf/hdrf_test.go +++ b/pkg/scheduler/plugins/drf/hdrf_test.go @@ -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 { diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go index e2e123e201..828258c1a5 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_best_effort_test.go @@ -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 @@ -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) { diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go new file mode 100644 index 0000000000..43c6fe0055 --- /dev/null +++ b/pkg/scheduler/plugins/numaaware/policy/policy_none_test.go @@ -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) + } + } +} diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go index 2e2d2c030b..c1054bfa29 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_restricted_test.go @@ -24,7 +24,7 @@ import ( ) func Test_restricted_predicate(t *testing.T) { - teseCases := []struct { + testCases := []struct { name string providersHints []map[string][]TopologyHint expect TopologyHint @@ -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) { diff --git a/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go b/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go index 1638b6ab09..5b041b9a68 100644 --- a/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go +++ b/pkg/scheduler/plugins/numaaware/policy/policy_single_numa_node_test.go @@ -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 @@ -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) { diff --git a/pkg/scheduler/plugins/predicates/predicates_test.go b/pkg/scheduler/plugins/predicates/predicates_test.go index 70bc1bff00..2525912922 100644 --- a/pkg/scheduler/plugins/predicates/predicates_test.go +++ b/pkg/scheduler/plugins/predicates/predicates_test.go @@ -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 { diff --git a/pkg/scheduler/uthelper/helper.go b/pkg/scheduler/uthelper/helper.go index a3fb030ec6..83bb4cb6c2 100644 --- a/pkg/scheduler/uthelper/helper.go +++ b/pkg/scheduler/uthelper/helper.go @@ -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) } @@ -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), @@ -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) diff --git a/pkg/scheduler/uthelper/interface.go b/pkg/scheduler/uthelper/interface.go index b67d8c1761..9fbf21e5ee 100644 --- a/pkg/scheduler/uthelper/interface.go +++ b/pkg/scheduler/uthelper/interface.go @@ -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