mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Integration framework table-tests standarization
This commit is contained in:
parent
4c8e5c5a50
commit
fcb41d3d2c
@ -22,13 +22,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
scheduler "k8s.io/kubernetes/pkg/scheduler"
|
"k8s.io/kubernetes/pkg/scheduler"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
@ -530,24 +530,29 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "disable fail and reject flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: false,
|
reject: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "enable fail and disable reject flags",
|
||||||
fail: true,
|
fail: true,
|
||||||
reject: false,
|
reject: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "disable fail and enable reject flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: true,
|
reject: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
preFilterPlugin.failPreFilter = test.fail
|
preFilterPlugin.failPreFilter = test.fail
|
||||||
preFilterPlugin.rejectPreFilter = test.reject
|
preFilterPlugin.rejectPreFilter = test.reject
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
@ -559,11 +564,11 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
|
|
||||||
if test.reject || test.fail {
|
if test.reject || test.fail {
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,6 +578,7 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
|
|
||||||
preFilterPlugin.reset()
|
preFilterPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,8 +708,23 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
for i, fail := range []bool{false, true} {
|
tests := []struct {
|
||||||
scorePlugin.failScore = fail
|
name string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fail score plugin",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "do not fail score plugin",
|
||||||
|
fail: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
scorePlugin.failScore = test.fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -711,9 +732,9 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
t.Fatalf("Error while creating a test pod: %v", err)
|
t.Fatalf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if test.fail {
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
@ -734,6 +755,7 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
|
|
||||||
scorePlugin.reset()
|
scorePlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,8 +831,23 @@ func TestReservePlugin(t *testing.T) {
|
|||||||
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
tests := []struct {
|
||||||
reservePlugin.failReserve = fail
|
name string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fail reserve plugin",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "do not fail reserve plugin",
|
||||||
|
fail: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
reservePlugin.failReserve = test.fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -818,7 +855,7 @@ func TestReservePlugin(t *testing.T) {
|
|||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if test.fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
|
||||||
podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
@ -835,6 +872,7 @@ func TestReservePlugin(t *testing.T) {
|
|||||||
|
|
||||||
reservePlugin.reset()
|
reservePlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -865,28 +903,34 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "disable fail and reject flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: false,
|
reject: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "enable fail and disable reject flags",
|
||||||
fail: true,
|
fail: true,
|
||||||
reject: false,
|
reject: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "disable fail and enable reject flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: true,
|
reject: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "enable fail and reject flags",
|
||||||
fail: true,
|
fail: true,
|
||||||
reject: true,
|
reject: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
preBindPlugin.failPreBind = test.fail
|
preBindPlugin.failPreBind = test.fail
|
||||||
preBindPlugin.rejectPreBind = test.reject
|
preBindPlugin.rejectPreBind = test.reject
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
@ -898,10 +942,10 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
|
|
||||||
if test.fail || test.reject {
|
if test.fail || test.reject {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("Expected a scheduling error, but didn't get it. error: %v", err)
|
||||||
}
|
}
|
||||||
} else if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
} else if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if preBindPlugin.numPreBindCalled == 0 {
|
if preBindPlugin.numPreBindCalled == 0 {
|
||||||
@ -910,6 +954,7 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
|
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,19 +996,22 @@ func TestUnreservePlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
preBindFail bool
|
preBindFail bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
preBindFail: false,
|
name: "fail preBind unreserve plugin",
|
||||||
|
preBindFail: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
preBindFail: true,
|
name: "do not fail preBind unreserve plugin",
|
||||||
|
preBindFail: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
preBindPlugin.failPreBind = test.preBindFail
|
preBindPlugin.failPreBind = test.preBindFail
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -973,23 +1021,24 @@ func TestUnreservePlugin(t *testing.T) {
|
|||||||
|
|
||||||
if test.preBindFail {
|
if test.preBindFail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("Expected a scheduling error, but didn't get it. error: %v", err)
|
||||||
}
|
}
|
||||||
if unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != preBindPlugin.numPreBindCalled {
|
if unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != preBindPlugin.numPreBindCalled {
|
||||||
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
|
t.Errorf("Expected the unreserve plugin to be called %d times, was called %d times.", preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if unreservePlugin.numUnreserveCalled > 0 {
|
if unreservePlugin.numUnreserveCalled > 0 {
|
||||||
t.Errorf("test #%v: Didn't expected the unreserve plugin to be called, was called %d times.", i, unreservePlugin.numUnreserveCalled)
|
t.Errorf("Didn't expect the unreserve plugin to be called, was called %d times.", unreservePlugin.numUnreserveCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unreservePlugin.reset()
|
unreservePlugin.reset()
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1054,45 +1103,48 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
bindPluginStatuses []*framework.Status
|
bindPluginStatuses []*framework.Status
|
||||||
expectBoundByScheduler bool // true means this test case expecting scheduler would bind pods
|
expectBoundByScheduler bool // true means this test case expecting scheduler would bind pods
|
||||||
expectBoundByPlugin bool // true means this test case expecting a plugin would bind pods
|
expectBoundByPlugin bool // true means this test case expecting a plugin would bind pods
|
||||||
expectBindPluginName string // expecting plugin name to bind pods
|
expectBindPluginName string // expecting plugin name to bind pods
|
||||||
expectInvokeEvents []pluginInvokeEvent
|
expectInvokeEvents []pluginInvokeEvent
|
||||||
}{
|
}{
|
||||||
// bind plugins skipped to bind the pod and scheduler bond the pod
|
|
||||||
{
|
{
|
||||||
|
name: "bind plugins skipped to bind the pod and scheduler bond the pod",
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Skip, "")},
|
||||||
expectBoundByScheduler: true,
|
expectBoundByScheduler: true,
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
||||||
},
|
},
|
||||||
// bindplugin2 succeeded to bind the pod
|
|
||||||
{
|
{
|
||||||
|
name: "bindplugin2 succeeded to bind the pod",
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Skip, ""), framework.NewStatus(framework.Success, "")},
|
||||||
expectBoundByPlugin: true,
|
expectBoundByPlugin: true,
|
||||||
expectBindPluginName: bindPlugin2.Name(),
|
expectBindPluginName: bindPlugin2.Name(),
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: bindPlugin2.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
||||||
},
|
},
|
||||||
// bindplugin1 succeeded to bind the pod
|
|
||||||
{
|
{
|
||||||
|
name: "bindplugin1 succeeded to bind the pod",
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Success, ""), framework.NewStatus(framework.Success, "")},
|
||||||
expectBoundByPlugin: true,
|
expectBoundByPlugin: true,
|
||||||
expectBindPluginName: bindPlugin1.Name(),
|
expectBindPluginName: bindPlugin1.Name(),
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: postBindPlugin.Name(), val: 1}},
|
||||||
},
|
},
|
||||||
// bind plugin fails to bind the pod
|
|
||||||
{
|
{
|
||||||
|
name: "bind plugin fails to bind the pod",
|
||||||
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Error, "failed to bind"), framework.NewStatus(framework.Success, "")},
|
bindPluginStatuses: []*framework.Status{framework.NewStatus(framework.Error, "failed to bind"), framework.NewStatus(framework.Success, "")},
|
||||||
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: unreservePlugin.Name(), val: 1}, {pluginName: bindPlugin1.Name(), val: 2}, {pluginName: unreservePlugin.Name(), val: 2}},
|
expectInvokeEvents: []pluginInvokeEvent{{pluginName: bindPlugin1.Name(), val: 1}, {pluginName: unreservePlugin.Name(), val: 1}, {pluginName: bindPlugin1.Name(), val: 2}, {pluginName: unreservePlugin.Name(), val: 2}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginInvokeEventChan chan pluginInvokeEvent
|
var pluginInvokeEventChan chan pluginInvokeEvent
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
pluginInvokeEventChan = make(chan pluginInvokeEvent, 10)
|
||||||
|
|
||||||
bindPlugin1.bindStatus = test.bindPluginStatuses[0]
|
bindPlugin1.bindStatus = test.bindPluginStatuses[0]
|
||||||
bindPlugin2.bindStatus = test.bindPluginStatuses[1]
|
bindPlugin2.bindStatus = test.bindPluginStatuses[1]
|
||||||
|
|
||||||
pluginInvokeEventChan = make(chan pluginInvokeEvent, 10)
|
|
||||||
bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan
|
bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan
|
||||||
bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan
|
bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan
|
||||||
unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan
|
unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan
|
||||||
@ -1108,8 +1160,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
if test.expectBoundByScheduler || test.expectBoundByPlugin {
|
if test.expectBoundByScheduler || test.expectBoundByPlugin {
|
||||||
// bind plugins skipped to bind the pod
|
// bind plugins skipped to bind the pod
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Fatalf("Expected the pod to be scheduled. error: %v", err)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1117,38 +1168,38 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
if test.expectBoundByScheduler {
|
if test.expectBoundByScheduler {
|
||||||
if pod.Annotations[bindPluginAnnotation] != "" {
|
if pod.Annotations[bindPluginAnnotation] != "" {
|
||||||
t.Errorf("test #%v: Expected the pod to be bound by scheduler instead of by bindplugin %s", i, pod.Annotations[bindPluginAnnotation])
|
t.Errorf("Expected the pod to be bound by scheduler instead of by bindplugin %s", pod.Annotations[bindPluginAnnotation])
|
||||||
}
|
}
|
||||||
if bindPlugin1.numBindCalled != 1 || bindPlugin2.numBindCalled != 1 {
|
if bindPlugin1.numBindCalled != 1 || bindPlugin2.numBindCalled != 1 {
|
||||||
t.Errorf("test #%v: Expected each bind plugin to be called once, was called %d and %d times.", i, bindPlugin1.numBindCalled, bindPlugin2.numBindCalled)
|
t.Errorf("Expected each bind plugin to be called once, was called %d and %d times.", bindPlugin1.numBindCalled, bindPlugin2.numBindCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if pod.Annotations[bindPluginAnnotation] != test.expectBindPluginName {
|
if pod.Annotations[bindPluginAnnotation] != test.expectBindPluginName {
|
||||||
t.Errorf("test #%v: Expected the pod to be bound by bindplugin %s instead of by bindplugin %s", i, test.expectBindPluginName, pod.Annotations[bindPluginAnnotation])
|
t.Errorf("Expected the pod to be bound by bindplugin %s instead of by bindplugin %s", test.expectBindPluginName, pod.Annotations[bindPluginAnnotation])
|
||||||
}
|
}
|
||||||
if bindPlugin1.numBindCalled != 1 {
|
if bindPlugin1.numBindCalled != 1 {
|
||||||
t.Errorf("test #%v: Expected %s to be called once, was called %d times.", i, bindPlugin1.Name(), bindPlugin1.numBindCalled)
|
t.Errorf("Expected %s to be called once, was called %d times.", bindPlugin1.Name(), bindPlugin1.numBindCalled)
|
||||||
}
|
}
|
||||||
if test.expectBindPluginName == bindPlugin1.Name() && bindPlugin2.numBindCalled > 0 {
|
if test.expectBindPluginName == bindPlugin1.Name() && bindPlugin2.numBindCalled > 0 {
|
||||||
// expect bindplugin1 succeeded to bind the pod and bindplugin2 should not be called.
|
// expect bindplugin1 succeeded to bind the pod and bindplugin2 should not be called.
|
||||||
t.Errorf("test #%v: Expected %s not to be called, was called %d times.", i, bindPlugin2.Name(), bindPlugin1.numBindCalled)
|
t.Errorf("Expected %s not to be called, was called %d times.", bindPlugin2.Name(), bindPlugin1.numBindCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, func() (done bool, err error) {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, func() (done bool, err error) {
|
||||||
return postBindPlugin.numPostBindCalled == 1, nil
|
return postBindPlugin.numPostBindCalled == 1, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Errorf("test #%v: Expected the postbind plugin to be called once, was called %d times.", i, postBindPlugin.numPostBindCalled)
|
t.Errorf("Expected the postbind plugin to be called once, was called %d times.", postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
if unreservePlugin.numUnreserveCalled != 0 {
|
if unreservePlugin.numUnreserveCalled != 0 {
|
||||||
t.Errorf("test #%v: Expected the unreserve plugin not to be called, was called %d times.", i, unreservePlugin.numUnreserveCalled)
|
t.Errorf("Expected the unreserve plugin not to be called, was called %d times.", unreservePlugin.numUnreserveCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// bind plugin fails to bind the pod
|
// bind plugin fails to bind the pod
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("Expected a scheduling error, but didn't get it. error: %v", err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled > 0 {
|
if postBindPlugin.numPostBindCalled > 0 {
|
||||||
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
|
t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for j := range test.expectInvokeEvents {
|
for j := range test.expectInvokeEvents {
|
||||||
@ -1156,13 +1207,13 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case event := <-pluginInvokeEventChan:
|
case event := <-pluginInvokeEventChan:
|
||||||
if event.pluginName != expectEvent.pluginName {
|
if event.pluginName != expectEvent.pluginName {
|
||||||
t.Errorf("test #%v: Expect invoke event %d from plugin %s instead of %s", i, j, expectEvent.pluginName, event.pluginName)
|
t.Errorf("Expect invoke event %d from plugin %s instead of %s", j, expectEvent.pluginName, event.pluginName)
|
||||||
}
|
}
|
||||||
if event.val != expectEvent.val {
|
if event.val != expectEvent.val {
|
||||||
t.Errorf("test #%v: Expect val of invoke event %d to be %d instead of %d", i, j, expectEvent.val, event.val)
|
t.Errorf("Expect val of invoke event %d to be %d instead of %d", j, expectEvent.val, event.val)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second * 30):
|
case <-time.After(time.Second * 30):
|
||||||
t.Errorf("test #%v: Waiting for invoke event %d timeout.", i, j)
|
t.Errorf("Waiting for invoke event %d timeout.", j)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
postBindPlugin.reset()
|
postBindPlugin.reset()
|
||||||
@ -1170,6 +1221,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
bindPlugin2.reset()
|
bindPlugin2.reset()
|
||||||
unreservePlugin.reset()
|
unreservePlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1211,20 +1263,23 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
preBindFail bool
|
preBindFail bool
|
||||||
preBindReject bool
|
preBindReject bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
preBindFail: false,
|
name: "plugin preBind fail",
|
||||||
|
preBindFail: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
preBindFail: true,
|
name: "plugin preBind do not fail",
|
||||||
|
preBindFail: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
preBindPlugin.failPreBind = test.preBindFail
|
preBindPlugin.failPreBind = test.preBindFail
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -1234,23 +1289,24 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
|
|
||||||
if test.preBindFail {
|
if test.preBindFail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("Expected a scheduling error, but didn't get it. error: %v", err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled > 0 {
|
if postBindPlugin.numPostBindCalled > 0 {
|
||||||
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
|
t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled == 0 {
|
if postBindPlugin.numPostBindCalled == 0 {
|
||||||
t.Errorf("test #%v: Expected the postbind plugin to be called, was called %d times.", i, postBindPlugin.numPostBindCalled)
|
t.Errorf("Expected the postbind plugin to be called, was called %d times.", postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postBindPlugin.reset()
|
postBindPlugin.reset()
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1267,43 +1323,51 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
timeout bool
|
timeout bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "disable fail, reject and timeout flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: false,
|
reject: false,
|
||||||
timeout: false,
|
timeout: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "enable fail, disable reject and timeout flags",
|
||||||
fail: true,
|
fail: true,
|
||||||
reject: false,
|
reject: false,
|
||||||
timeout: false,
|
timeout: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "disable fail and timeout, enable reject flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: true,
|
reject: true,
|
||||||
timeout: false,
|
timeout: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "enable fail and reject, disable timeout flags",
|
||||||
fail: true,
|
fail: true,
|
||||||
reject: true,
|
reject: true,
|
||||||
timeout: false,
|
timeout: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "disable fail and reject, disable timeout flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: false,
|
reject: false,
|
||||||
timeout: true,
|
timeout: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "disable fail and reject, enable timeout flags",
|
||||||
fail: false,
|
fail: false,
|
||||||
reject: false,
|
reject: false,
|
||||||
timeout: true,
|
timeout: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
perPlugin.failPermit = test.fail
|
perPlugin.failPermit = test.fail
|
||||||
perPlugin.rejectPermit = test.reject
|
perPlugin.rejectPermit = test.reject
|
||||||
perPlugin.timeoutPermit = test.timeout
|
perPlugin.timeoutPermit = test.timeout
|
||||||
@ -1318,16 +1382,16 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
if test.fail {
|
if test.fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("Expected a scheduling error, but didn't get it. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if test.reject || test.timeout {
|
if test.reject || test.timeout {
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1338,6 +1402,7 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
|
|
||||||
perPlugin.reset()
|
perPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1452,20 +1517,24 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
waitReject bool
|
waitReject bool
|
||||||
waitAllow bool
|
waitAllow bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "having wait reject true and wait allow false",
|
||||||
waitReject: true,
|
waitReject: true,
|
||||||
waitAllow: false,
|
waitAllow: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "having wait reject false and wait allow true",
|
||||||
waitReject: false,
|
waitReject: false,
|
||||||
waitAllow: true,
|
waitAllow: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
permitPlugin.failPermit = false
|
permitPlugin.failPermit = false
|
||||||
permitPlugin.rejectPermit = false
|
permitPlugin.rejectPermit = false
|
||||||
permitPlugin.timeoutPermit = false
|
permitPlugin.timeoutPermit = false
|
||||||
@ -1487,27 +1556,27 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
|
|
||||||
if test.waitReject {
|
if test.waitReject {
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, podA); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, podA); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the first pod to be scheduled. error: %v", i, err)
|
t.Errorf("Didn't expect the first pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, podB); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, podB); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the second pod to be scheduled. error: %v", i, err)
|
t.Errorf("Didn't expect the second pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if !((permitPlugin.waitingPod == podA.Name && permitPlugin.rejectingPod == podB.Name) ||
|
if !((permitPlugin.waitingPod == podA.Name && permitPlugin.rejectingPod == podB.Name) ||
|
||||||
(permitPlugin.waitingPod == podB.Name && permitPlugin.rejectingPod == podA.Name)) {
|
(permitPlugin.waitingPod == podB.Name && permitPlugin.rejectingPod == podA.Name)) {
|
||||||
t.Errorf("test #%v: Expect one pod to wait and another pod to reject instead %s waited and %s rejected.",
|
t.Errorf("Expect one pod to wait and another pod to reject instead %s waited and %s rejected.",
|
||||||
i, permitPlugin.waitingPod, permitPlugin.rejectingPod)
|
permitPlugin.waitingPod, permitPlugin.rejectingPod)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podA); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podA); err != nil {
|
||||||
t.Errorf("test #%v: Expected the first pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the first pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podB); err != nil {
|
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podB); err != nil {
|
||||||
t.Errorf("test #%v: Expected the second pod to be scheduled. error: %v", i, err)
|
t.Errorf("Expected the second pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
if !((permitPlugin.waitingPod == podA.Name && permitPlugin.allowingPod == podB.Name) ||
|
if !((permitPlugin.waitingPod == podA.Name && permitPlugin.allowingPod == podB.Name) ||
|
||||||
(permitPlugin.waitingPod == podB.Name && permitPlugin.allowingPod == podA.Name)) {
|
(permitPlugin.waitingPod == podB.Name && permitPlugin.allowingPod == podA.Name)) {
|
||||||
t.Errorf("test #%v: Expect one pod to wait and another pod to allow instead %s waited and %s allowed.",
|
t.Errorf("Expect one pod to wait and another pod to allow instead %s waited and %s allowed.",
|
||||||
i, permitPlugin.waitingPod, permitPlugin.allowingPod)
|
permitPlugin.waitingPod, permitPlugin.allowingPod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1517,6 +1586,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
|
|
||||||
permitPlugin.reset()
|
permitPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{podA, podB})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{podA, podB})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,8 +1616,23 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
tests := []struct {
|
||||||
filterPlugin.failFilter = fail
|
name string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fail filter plugin",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "do not fail filter plugin",
|
||||||
|
fail: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
filterPlugin.failFilter = test.fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -1555,7 +1640,7 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if test.fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled.")
|
t.Errorf("Didn't expect the pod to be scheduled.")
|
||||||
}
|
}
|
||||||
@ -1571,6 +1656,7 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
|
|
||||||
filterPlugin.reset()
|
filterPlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1600,8 +1686,23 @@ func TestPreScorePlugin(t *testing.T) {
|
|||||||
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
scheduler.WithFrameworkOutOfTreeRegistry(registry))
|
||||||
defer testutils.CleanupTest(t, testCtx)
|
defer testutils.CleanupTest(t, testCtx)
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
tests := []struct {
|
||||||
preScorePlugin.failPreScore = fail
|
name string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fail preScore plugin",
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "do not fail preScore plugin",
|
||||||
|
fail: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
preScorePlugin.failPreScore = test.fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(testCtx.ClientSet,
|
pod, err := createPausePod(testCtx.ClientSet,
|
||||||
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
|
||||||
@ -1609,7 +1710,7 @@ func TestPreScorePlugin(t *testing.T) {
|
|||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if test.fail {
|
||||||
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
@ -1625,6 +1726,7 @@ func TestPreScorePlugin(t *testing.T) {
|
|||||||
|
|
||||||
preScorePlugin.reset()
|
preScorePlugin.reset()
|
||||||
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user