Integration framework table-tests standarization

This commit is contained in:
Amim Knabben 2020-06-05 13:36:42 -04:00
parent 4c8e5c5a50
commit fcb41d3d2c

View File

@ -22,13 +22,13 @@ import (
"testing"
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
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"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
@ -530,24 +530,29 @@ func TestPreFilterPlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
fail bool
reject bool
}{
{
name: "disable fail and reject flags",
fail: false,
reject: false,
},
{
name: "enable fail and disable reject flags",
fail: true,
reject: false,
},
{
name: "disable fail and enable reject flags",
fail: false,
reject: true,
},
}
for i, test := range tests {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
preFilterPlugin.failPreFilter = test.fail
preFilterPlugin.rejectPreFilter = test.reject
// Create a best effort pod.
@ -559,11 +564,11 @@ func TestPreFilterPlugin(t *testing.T) {
if test.reject || test.fail {
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 {
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()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -702,8 +708,23 @@ func TestScorePlugin(t *testing.T) {
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer testutils.CleanupTest(t, testCtx)
for i, fail := range []bool{false, true} {
scorePlugin.failScore = fail
tests := []struct {
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.
pod, err := createPausePod(testCtx.ClientSet,
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)
}
if fail {
if test.fail {
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 {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
@ -734,6 +755,7 @@ func TestScorePlugin(t *testing.T) {
scorePlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -809,8 +831,23 @@ func TestReservePlugin(t *testing.T) {
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
reservePlugin.failReserve = fail
tests := []struct {
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.
pod, err := createPausePod(testCtx.ClientSet,
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)
}
if fail {
if test.fail {
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
@ -835,6 +872,7 @@ func TestReservePlugin(t *testing.T) {
reservePlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -865,28 +903,34 @@ func TestPrebindPlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
fail bool
reject bool
}{
{
name: "disable fail and reject flags",
fail: false,
reject: false,
},
{
name: "enable fail and disable reject flags",
fail: true,
reject: false,
},
{
name: "disable fail and enable reject flags",
fail: false,
reject: true,
},
{
name: "enable fail and reject flags",
fail: 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.rejectPreBind = test.reject
// Create a best effort pod.
@ -898,10 +942,10 @@ func TestPrebindPlugin(t *testing.T) {
if test.fail || test.reject {
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 {
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 {
@ -910,6 +954,7 @@ func TestPrebindPlugin(t *testing.T) {
preBindPlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -951,19 +996,22 @@ func TestUnreservePlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
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
// Create a best effort pod.
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
@ -973,23 +1021,24 @@ func TestUnreservePlugin(t *testing.T) {
if test.preBindFail {
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 {
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 {
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 {
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()
preBindPlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -1054,45 +1103,48 @@ func TestBindPlugin(t *testing.T) {
}
tests := []struct {
name string
bindPluginStatuses []*framework.Status
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
expectBindPluginName string // expecting plugin name to bind pods
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, "")},
expectBoundByScheduler: true,
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, "")},
expectBoundByPlugin: true,
expectBindPluginName: bindPlugin2.Name(),
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, "")},
expectBoundByPlugin: true,
expectBindPluginName: bindPlugin1.Name(),
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, "")},
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
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]
bindPlugin2.bindStatus = test.bindPluginStatuses[1]
pluginInvokeEventChan = make(chan pluginInvokeEvent, 10)
bindPlugin1.pluginInvokeEventChan = pluginInvokeEventChan
bindPlugin2.pluginInvokeEventChan = pluginInvokeEventChan
unreservePlugin.pluginInvokeEventChan = pluginInvokeEventChan
@ -1108,8 +1160,7 @@ func TestBindPlugin(t *testing.T) {
if test.expectBoundByScheduler || test.expectBoundByPlugin {
// bind plugins skipped to bind the pod
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
continue
t.Fatalf("Expected the pod to be scheduled. error: %v", err)
}
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
if err != nil {
@ -1117,38 +1168,38 @@ func TestBindPlugin(t *testing.T) {
}
if test.expectBoundByScheduler {
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 {
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 {
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 {
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 {
// 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) {
return postBindPlugin.numPostBindCalled == 1, 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 {
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 {
// 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 {
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 {
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 {
@ -1156,13 +1207,13 @@ func TestBindPlugin(t *testing.T) {
select {
case event := <-pluginInvokeEventChan:
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 {
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):
t.Errorf("test #%v: Waiting for invoke event %d timeout.", i, j)
t.Errorf("Waiting for invoke event %d timeout.", j)
}
}
postBindPlugin.reset()
@ -1170,6 +1221,7 @@ func TestBindPlugin(t *testing.T) {
bindPlugin2.reset()
unreservePlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -1211,20 +1263,23 @@ func TestPostBindPlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
preBindFail 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
// Create a best effort pod.
pod, err := createPausePod(testCtx.ClientSet,
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
@ -1234,23 +1289,24 @@ func TestPostBindPlugin(t *testing.T) {
if test.preBindFail {
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 {
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 {
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 {
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()
preBindPlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -1267,43 +1323,51 @@ func TestPermitPlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
fail bool
reject bool
timeout bool
}{
{
name: "disable fail, reject and timeout flags",
fail: false,
reject: false,
timeout: false,
},
{
name: "enable fail, disable reject and timeout flags",
fail: true,
reject: false,
timeout: false,
},
{
name: "disable fail and timeout, enable reject flags",
fail: false,
reject: true,
timeout: false,
},
{
name: "enable fail and reject, disable timeout flags",
fail: true,
reject: true,
timeout: false,
},
{
name: "disable fail and reject, disable timeout flags",
fail: false,
reject: false,
timeout: true,
},
{
name: "disable fail and reject, enable timeout flags",
fail: false,
reject: false,
timeout: true,
},
}
for i, test := range tests {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
perPlugin.failPermit = test.fail
perPlugin.rejectPermit = test.reject
perPlugin.timeoutPermit = test.timeout
@ -1318,16 +1382,16 @@ func TestPermitPlugin(t *testing.T) {
}
if test.fail {
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 test.reject || test.timeout {
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 {
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()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -1452,20 +1517,24 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
waitReject bool
waitAllow bool
}{
{
name: "having wait reject true and wait allow false",
waitReject: true,
waitAllow: false,
},
{
name: "having wait reject false and wait allow true",
waitReject: false,
waitAllow: true,
},
}
for i, test := range tests {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
permitPlugin.failPermit = false
permitPlugin.rejectPermit = false
permitPlugin.timeoutPermit = false
@ -1487,27 +1556,27 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
if test.waitReject {
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 {
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) ||
(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.",
i, permitPlugin.waitingPod, permitPlugin.rejectingPod)
t.Errorf("Expect one pod to wait and another pod to reject instead %s waited and %s rejected.",
permitPlugin.waitingPod, permitPlugin.rejectingPod)
}
} else {
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 {
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) ||
(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.",
i, permitPlugin.waitingPod, permitPlugin.allowingPod)
t.Errorf("Expect one pod to wait and another pod to allow instead %s waited and %s allowed.",
permitPlugin.waitingPod, permitPlugin.allowingPod)
}
}
@ -1517,6 +1586,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
permitPlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{podA, podB})
})
}
}
@ -1546,8 +1616,23 @@ func TestFilterPlugin(t *testing.T) {
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
filterPlugin.failFilter = fail
tests := []struct {
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.
pod, err := createPausePod(testCtx.ClientSet,
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)
}
if fail {
if test.fail {
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.")
}
@ -1571,6 +1656,7 @@ func TestFilterPlugin(t *testing.T) {
filterPlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}
@ -1600,8 +1686,23 @@ func TestPreScorePlugin(t *testing.T) {
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer testutils.CleanupTest(t, testCtx)
for _, fail := range []bool{false, true} {
preScorePlugin.failPreScore = fail
tests := []struct {
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.
pod, err := createPausePod(testCtx.ClientSet,
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)
}
if fail {
if test.fail {
if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
}
@ -1625,6 +1726,7 @@ func TestPreScorePlugin(t *testing.T) {
preScorePlugin.reset()
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
})
}
}