mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2026-01-08 00:01:40 +00:00
Enable testing logger in the remaining scheduler tests.
This commit is contained in:
@@ -951,6 +951,7 @@ func TestPreEnqueuePlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
cfgPls := &config.Plugins{}
|
||||
for _, pl := range tt.plugins {
|
||||
@@ -969,7 +970,7 @@ func TestPreEnqueuePlugins(t *testing.T) {
|
||||
)
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
if err != nil {
|
||||
@@ -1089,7 +1090,8 @@ func TestRunPreScorePlugins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(
|
||||
@@ -1490,7 +1492,8 @@ func TestRunScorePlugins(t *testing.T) {
|
||||
Plugins: tt.plugins,
|
||||
PluginConfig: tt.pluginConfigs,
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
if err != nil {
|
||||
@@ -1536,7 +1539,8 @@ func TestPreFilterPlugins(t *testing.T) {
|
||||
plugins := &config.Plugins{PreFilter: config.PluginSet{Enabled: []config.Plugin{{Name: preFilterWithExtensionsPluginName}, {Name: preFilterPluginName}}}}
|
||||
t.Run("TestPreFilterPlugin", func(t *testing.T) {
|
||||
profile := config.KubeSchedulerProfile{Plugins: plugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, r, profile)
|
||||
@@ -1723,7 +1727,8 @@ func TestRunPreFilterPlugins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(
|
||||
@@ -1816,7 +1821,8 @@ func TestRunPreFilterExtensionRemovePod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(
|
||||
@@ -1903,7 +1909,8 @@ func TestRunPreFilterExtensionAddPod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(
|
||||
@@ -2096,6 +2103,7 @@ func TestFilterPlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
cfgPls := &config.Plugins{}
|
||||
for _, pl := range tt.plugins {
|
||||
@@ -2113,7 +2121,7 @@ func TestFilterPlugins(t *testing.T) {
|
||||
config.Plugin{Name: pl.name})
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
@@ -2223,6 +2231,7 @@ func TestPostFilterPlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
cfgPls := &config.Plugins{}
|
||||
for _, pl := range tt.plugins {
|
||||
@@ -2241,7 +2250,7 @@ func TestPostFilterPlugins(t *testing.T) {
|
||||
)
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
if err != nil {
|
||||
@@ -2358,7 +2367,7 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
logger, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
cfgPls := &config.Plugins{}
|
||||
|
||||
@@ -2408,7 +2417,7 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) {
|
||||
&framework.NominatingInfo{NominatingMode: framework.ModeOverride, NominatedNodeName: nodeName})
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: cfgPls}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile, WithPodNominator(podNominator))
|
||||
if err != nil {
|
||||
@@ -2551,6 +2560,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
configPlugins := &config.Plugins{}
|
||||
|
||||
@@ -2568,7 +2578,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
)
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
if err != nil {
|
||||
@@ -2712,6 +2722,7 @@ func TestReservePlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
configPlugins := &config.Plugins{}
|
||||
|
||||
@@ -2729,7 +2740,7 @@ func TestReservePlugins(t *testing.T) {
|
||||
)
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
|
||||
defer func() {
|
||||
@@ -2841,6 +2852,7 @@ func TestPermitPlugins(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
registry := Registry{}
|
||||
configPlugins := &config.Plugins{}
|
||||
|
||||
@@ -2858,7 +2870,7 @@ func TestPermitPlugins(t *testing.T) {
|
||||
)
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: configPlugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile,
|
||||
WithWaitingPods(NewWaitingPodsMap()),
|
||||
@@ -2891,86 +2903,86 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
action func(f framework.Framework)
|
||||
action func(ctx context.Context, f framework.Framework)
|
||||
inject injectedResult
|
||||
wantExtensionPoint string
|
||||
wantStatus framework.Code
|
||||
}{
|
||||
{
|
||||
name: "PreFilter - Success",
|
||||
action: func(f framework.Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreFilterPlugins(ctx, state, pod) },
|
||||
wantExtensionPoint: "PreFilter",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "PreScore - Success",
|
||||
action: func(f framework.Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreScorePlugins(ctx, state, pod, nil) },
|
||||
wantExtensionPoint: "PreScore",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "Score - Success",
|
||||
action: func(f framework.Framework) {
|
||||
f.RunScorePlugins(context.Background(), state, pod, BuildNodeInfos(nodes))
|
||||
action: func(ctx context.Context, f framework.Framework) {
|
||||
f.RunScorePlugins(ctx, state, pod, BuildNodeInfos(nodes))
|
||||
},
|
||||
wantExtensionPoint: "Score",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "Reserve - Success",
|
||||
action: func(f framework.Framework) { f.RunReservePluginsReserve(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunReservePluginsReserve(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "Reserve",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "Unreserve - Success",
|
||||
action: func(f framework.Framework) { f.RunReservePluginsUnreserve(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunReservePluginsUnreserve(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "Unreserve",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "PreBind - Success",
|
||||
action: func(f framework.Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreBindPlugins(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "PreBind",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "Bind - Success",
|
||||
action: func(f framework.Framework) { f.RunBindPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunBindPlugins(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "Bind",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "PostBind - Success",
|
||||
action: func(f framework.Framework) { f.RunPostBindPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPostBindPlugins(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "PostBind",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
{
|
||||
name: "Permit - Success",
|
||||
action: func(f framework.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPermitPlugins(ctx, state, pod, "") },
|
||||
wantExtensionPoint: "Permit",
|
||||
wantStatus: framework.Success,
|
||||
},
|
||||
|
||||
{
|
||||
name: "PreFilter - Error",
|
||||
action: func(f framework.Framework) { f.RunPreFilterPlugins(context.Background(), state, pod) },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreFilterPlugins(ctx, state, pod) },
|
||||
inject: injectedResult{PreFilterStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "PreFilter",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "PreScore - Error",
|
||||
action: func(f framework.Framework) { f.RunPreScorePlugins(context.Background(), state, pod, nil) },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreScorePlugins(ctx, state, pod, nil) },
|
||||
inject: injectedResult{PreScoreStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "PreScore",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "Score - Error",
|
||||
action: func(f framework.Framework) {
|
||||
f.RunScorePlugins(context.Background(), state, pod, BuildNodeInfos(nodes))
|
||||
action: func(ctx context.Context, f framework.Framework) {
|
||||
f.RunScorePlugins(ctx, state, pod, BuildNodeInfos(nodes))
|
||||
},
|
||||
inject: injectedResult{ScoreStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "Score",
|
||||
@@ -2978,35 +2990,35 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Reserve - Error",
|
||||
action: func(f framework.Framework) { f.RunReservePluginsReserve(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunReservePluginsReserve(ctx, state, pod, "") },
|
||||
inject: injectedResult{ReserveStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "Reserve",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "PreBind - Error",
|
||||
action: func(f framework.Framework) { f.RunPreBindPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPreBindPlugins(ctx, state, pod, "") },
|
||||
inject: injectedResult{PreBindStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "PreBind",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "Bind - Error",
|
||||
action: func(f framework.Framework) { f.RunBindPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunBindPlugins(ctx, state, pod, "") },
|
||||
inject: injectedResult{BindStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "Bind",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "Permit - Error",
|
||||
action: func(f framework.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPermitPlugins(ctx, state, pod, "") },
|
||||
inject: injectedResult{PermitStatus: int(framework.Error)},
|
||||
wantExtensionPoint: "Permit",
|
||||
wantStatus: framework.Error,
|
||||
},
|
||||
{
|
||||
name: "Permit - Wait",
|
||||
action: func(f framework.Framework) { f.RunPermitPlugins(context.Background(), state, pod, "") },
|
||||
action: func(ctx context.Context, f framework.Framework) { f.RunPermitPlugins(ctx, state, pod, "") },
|
||||
inject: injectedResult{PermitStatus: int(framework.Wait)},
|
||||
wantExtensionPoint: "Permit",
|
||||
wantStatus: framework.Wait,
|
||||
@@ -3059,7 +3071,7 @@ func TestRecordingMetrics(t *testing.T) {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
tt.action(f)
|
||||
tt.action(ctx, f)
|
||||
|
||||
// Stop the goroutine which records metrics and ensure it's stopped.
|
||||
cancel()
|
||||
@@ -3175,7 +3187,7 @@ func TestRunBindPlugins(t *testing.T) {
|
||||
_ = fwk.Close()
|
||||
}()
|
||||
|
||||
st := fwk.RunBindPlugins(context.Background(), state, pod, "")
|
||||
st := fwk.RunBindPlugins(ctx, state, pod, "")
|
||||
if st.Code() != tt.wantStatus {
|
||||
t.Errorf("got status code %s, want %s", st.Code(), tt.wantStatus)
|
||||
}
|
||||
@@ -3208,6 +3220,7 @@ func TestPermitWaitDurationMetric(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
metrics.Register()
|
||||
metrics.PermitWaitDuration.Reset()
|
||||
|
||||
@@ -3224,7 +3237,7 @@ func TestPermitWaitDurationMetric(t *testing.T) {
|
||||
Permit: config.PluginSet{Enabled: []config.Plugin{{Name: testPlugin, Weight: 1}}},
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: plugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, r, profile,
|
||||
WithWaitingPods(NewWaitingPodsMap()),
|
||||
@@ -3275,6 +3288,7 @@ func TestWaitOnPermit(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
testPermitPlugin := &TestPermitPlugin{}
|
||||
r := make(Registry)
|
||||
r.Register(permitPlugin,
|
||||
@@ -3285,7 +3299,7 @@ func TestWaitOnPermit(t *testing.T) {
|
||||
Permit: config.PluginSet{Enabled: []config.Plugin{{Name: permitPlugin, Weight: 1}}},
|
||||
}
|
||||
profile := config.KubeSchedulerProfile{Plugins: plugins}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
f, err := newFrameworkWithQueueSortAndBind(ctx, r, profile,
|
||||
WithWaitingPods(NewWaitingPodsMap()),
|
||||
|
||||
Reference in New Issue
Block a user