Skip to content

Commit aab7a07

Browse files
committed
make each scheduler test independent
Signed-off-by: carlory <[email protected]>
1 parent 9acdca6 commit aab7a07

File tree

9 files changed

+28
-14
lines changed

9 files changed

+28
-14
lines changed

pkg/scheduler/backend/cache/cache_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var nodeInfoCmpOpts = []cmp.Option{
4646
cmpopts.IgnoreFields(framework.PodInfo{}, "cachedResource"),
4747
}
4848

49+
func init() {
50+
metrics.Register()
51+
}
52+
4953
func deepEqualWithoutGeneration(actual *nodeInfoListItem, expected *framework.NodeInfo) error {
5054
if (actual == nil) != (expected == nil) {
5155
return errors.New("one of the actual or expected is nil and the other is not")
@@ -273,7 +277,6 @@ func assumeAndFinishBinding(logger klog.Logger, cache *cacheImpl, pod *v1.Pod, a
273277
// TestExpirePod tests that assumed pods will be removed if expired.
274278
// The removal will be reflected in node info.
275279
func TestExpirePod(t *testing.T) {
276-
metrics.Register()
277280
nodeName := "node"
278281
testPods := []*v1.Pod{
279282
makeBasePod(t, nodeName, "test-1", "100m", "500", "", []v1.ContainerPort{{HostIP: "127.0.0.1", HostPort: 80, Protocol: "TCP"}}),

pkg/scheduler/backend/queue/active_queue_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
func TestClose(t *testing.T) {
3131
logger, ctx := ktesting.NewTestContext(t)
32-
metrics.Register()
3332
rr := metrics.NewMetricsAsyncRecorder(10, time.Second, ctx.Done())
3433
aq := newActiveQueue(heap.NewWithRecorder(podInfoKeyFunc, heap.LessFunc[*framework.QueuedPodInfo](newDefaultQueueSort()), metrics.NewActivePodsRecorder()), true, *rr)
3534

pkg/scheduler/eventhandlers_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import (
6060
)
6161

6262
func TestEventHandlers_MoveToActiveOnNominatedNodeUpdate(t *testing.T) {
63-
metrics.Register()
6463
highPriorityPod :=
6564
st.MakePod().Name("hpp").Namespace("ns1").UID("hppns1").Priority(highPriority).SchedulerName(testSchedulerName).Obj()
6665

@@ -210,7 +209,6 @@ func newDefaultQueueSort() framework.LessFunc {
210209
func TestUpdatePodInCache(t *testing.T) {
211210
ttl := 10 * time.Second
212211
nodeName := "node"
213-
metrics.Register()
214212

215213
tests := []struct {
216214
name string

pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ var (
9898
epochTime6 = metav1.NewTime(time.Unix(0, 6))
9999
)
100100

101+
func init() {
102+
metrics.Register()
103+
}
104+
101105
func getDefaultDefaultPreemptionArgs() *config.DefaultPreemptionArgs {
102106
v1dpa := &kubeschedulerconfigv1.DefaultPreemptionArgs{}
103107
configv1.SetDefaults_DefaultPreemptionArgs(v1dpa)
@@ -155,7 +159,6 @@ const (
155159
)
156160

157161
func TestPostFilter(t *testing.T) {
158-
metrics.Register()
159162
onePodRes := map[v1.ResourceName]string{v1.ResourcePods: "1"}
160163
nodeRes := map[v1.ResourceName]string{v1.ResourceCPU: "200m", v1.ResourceMemory: "400"}
161164
tests := []struct {
@@ -471,7 +474,6 @@ type candidate struct {
471474
}
472475

473476
func TestDryRunPreemption(t *testing.T) {
474-
metrics.Register()
475477
tests := []struct {
476478
name string
477479
args *config.DefaultPreemptionArgs

pkg/scheduler/framework/plugins/interpodaffinity/filtering_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var (
4343
}
4444
)
4545

46+
func init() {
47+
metrics.Register()
48+
}
49+
4650
func createPodWithAffinityTerms(namespace, nodeName string, labels map[string]string, affinity, antiAffinity []v1.PodAffinityTerm) *v1.Pod {
4751
return &v1.Pod{
4852
ObjectMeta: metav1.ObjectMeta{
@@ -73,7 +77,6 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
7377
}
7478
podLabel2 := map[string]string{"security": "S1"}
7579
node1 := v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: labels1}}
76-
metrics.Register()
7780

7881
tests := []struct {
7982
pod *v1.Pod

pkg/scheduler/framework/plugins/podtopologyspread/filtering_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ var (
6363
taints = []v1.Taint{{Key: v1.TaintNodeUnschedulable, Value: "", Effect: v1.TaintEffectNoSchedule}}
6464
)
6565

66+
func init() {
67+
metrics.Register()
68+
}
69+
6670
func (p *criticalPaths) sort() {
6771
if p[0].MatchNum == p[1].MatchNum && p[0].TopologyValue > p[1].TopologyValue {
6872
// Swap TopologyValue to make them sorted alphabetically.
@@ -71,7 +75,6 @@ func (p *criticalPaths) sort() {
7175
}
7276

7377
func TestPreFilterState(t *testing.T) {
74-
metrics.Register()
7578
tests := []struct {
7679
name string
7780
pod *v1.Pod
@@ -2316,7 +2319,6 @@ func TestPreFilterStateRemovePod(t *testing.T) {
23162319
}
23172320

23182321
func BenchmarkFilter(b *testing.B) {
2319-
metrics.Register()
23202322
tests := []struct {
23212323
name string
23222324
pod *v1.Pod

pkg/scheduler/framework/preemption/preemption_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ var (
6363
}
6464
)
6565

66+
func init() {
67+
metrics.Register()
68+
}
69+
6670
type FakePostFilterPlugin struct {
6771
numViolatingVictim int
6872
}
@@ -140,7 +144,6 @@ func (pl *FakePreemptionScorePostFilterPlugin) OrderedScoreFuncs(ctx context.Con
140144
}
141145

142146
func TestDryRunPreemption(t *testing.T) {
143-
metrics.Register()
144147
tests := []struct {
145148
name string
146149
nodes []*v1.Node

pkg/scheduler/framework/runtime/framework_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ const (
6666
injectFilterReason = "injected filter status"
6767
)
6868

69+
func init() {
70+
metrics.Register()
71+
}
72+
6973
// TestScoreWithNormalizePlugin implements ScoreWithNormalizePlugin interface.
7074
// TestScorePlugin only implements ScorePlugin interface.
7175
var _ framework.ScorePlugin = &TestScoreWithNormalizePlugin{}
@@ -460,7 +464,6 @@ func newFrameworkWithQueueSortAndBind(ctx context.Context, r Registry, profile c
460464
}
461465

462466
func TestInitFrameworkWithScorePlugins(t *testing.T) {
463-
metrics.Register()
464467
tests := []struct {
465468
name string
466469
plugins *config.Plugins
@@ -2905,7 +2908,6 @@ func withMetricsRecorder(recorder *metrics.MetricAsyncRecorder) Option {
29052908
func TestRecordingMetrics(t *testing.T) {
29062909
state := &framework.CycleState{}
29072910
state.SetRecordPluginMetrics(true)
2908-
metrics.Register()
29092911
tests := []struct {
29102912
name string
29112913
action func(ctx context.Context, f framework.Framework)
@@ -3089,7 +3091,6 @@ func TestRecordingMetrics(t *testing.T) {
30893091
}
30903092

30913093
func TestRunBindPlugins(t *testing.T) {
3092-
metrics.Register()
30933094
tests := []struct {
30943095
name string
30953096
injects []framework.Code
@@ -3206,7 +3207,6 @@ func TestRunBindPlugins(t *testing.T) {
32063207
}
32073208

32083209
func TestPermitWaitDurationMetric(t *testing.T) {
3209-
metrics.Register()
32103210
tests := []struct {
32113211
name string
32123212
inject injectedResult

pkg/scheduler/scheduler_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ import (
6464
utiltesting "k8s.io/kubernetes/test/utils/ktesting"
6565
)
6666

67+
func init() {
68+
metrics.Register()
69+
}
70+
6771
func TestSchedulerCreation(t *testing.T) {
6872
invalidRegistry := map[string]frameworkruntime.PluginFactory{
6973
defaultbinder.Name: defaultbinder.New,

0 commit comments

Comments
 (0)