fix(queue_test): make sure the first bind failure via counter
This commit is contained in:
@@ -445,9 +445,19 @@ func TestCustomResourceEnqueue(t *testing.T) {
|
|||||||
// TestRequeueByBindFailure verify Pods failed by bind plugin are
|
// TestRequeueByBindFailure verify Pods failed by bind plugin are
|
||||||
// put back to the queue regardless of whether event happens or not.
|
// put back to the queue regardless of whether event happens or not.
|
||||||
func TestRequeueByBindFailure(t *testing.T) {
|
func TestRequeueByBindFailure(t *testing.T) {
|
||||||
|
fakeBind := &firstFailBindPlugin{}
|
||||||
registry := frameworkruntime.Registry{
|
registry := frameworkruntime.Registry{
|
||||||
"firstFailBindPlugin": newFirstFailBindPlugin,
|
"firstFailBindPlugin": func(o runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
||||||
|
binder, err := defaultbinder.New(nil, fh)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fakeBind.defaultBinderPlugin = binder.(framework.BindPlugin)
|
||||||
|
return fakeBind, nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := configtesting.V1ToInternalWithDefaults(t, configv1.KubeSchedulerConfiguration{
|
cfg := configtesting.V1ToInternalWithDefaults(t, configv1.KubeSchedulerConfiguration{
|
||||||
Profiles: []configv1.KubeSchedulerProfile{{
|
Profiles: []configv1.KubeSchedulerProfile{{
|
||||||
SchedulerName: pointer.String(v1.DefaultSchedulerName),
|
SchedulerName: pointer.String(v1.DefaultSchedulerName),
|
||||||
@@ -488,16 +498,17 @@ func TestRequeueByBindFailure(t *testing.T) {
|
|||||||
t.Fatalf("Failed to create Pod %q: %v", pod.Name, err)
|
t.Fatalf("Failed to create Pod %q: %v", pod.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// first binding try should fail.
|
// 1. first binding try should fail.
|
||||||
err := wait.PollUntilContextTimeout(ctx, 200*time.Millisecond, wait.ForeverTestTimeout, false, testutils.PodSchedulingError(cs, ns, pod.Name))
|
// 2. The pod should be enqueued to activeQ/backoffQ without any event.
|
||||||
|
// 3. The pod should be scheduled in the second binding try.
|
||||||
|
// Here, waiting until (3).
|
||||||
|
err := wait.PollUntilContextTimeout(ctx, 200*time.Millisecond, wait.ForeverTestTimeout, false, testutils.PodScheduled(cs, ns, pod.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expect pod-1 to be rejected by the bind plugin: %v", err)
|
t.Fatalf("Expect pod-1 to be scheduled by the bind plugin: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The pod should be enqueued to activeQ/backoffQ without any event.
|
// Make sure the first binding trial was failed, and this pod is scheduled at the second trial.
|
||||||
// The pod should be scheduled in the second binding try.
|
if fakeBind.counter != 1 {
|
||||||
err = wait.PollUntilContextTimeout(ctx, 200*time.Millisecond, wait.ForeverTestTimeout, false, testutils.PodScheduled(cs, ns, pod.Name))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Expect pod-1 to be scheduled by the bind plugin in the second binding try: %v", err)
|
t.Fatalf("Expect pod-1 to be scheduled by the bind plugin in the second binding try: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,17 +519,6 @@ type firstFailBindPlugin struct {
|
|||||||
defaultBinderPlugin framework.BindPlugin
|
defaultBinderPlugin framework.BindPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFirstFailBindPlugin(_ runtime.Object, handle framework.Handle) (framework.Plugin, error) {
|
|
||||||
binder, err := defaultbinder.New(nil, handle)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &firstFailBindPlugin{
|
|
||||||
defaultBinderPlugin: binder.(framework.BindPlugin),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*firstFailBindPlugin) Name() string {
|
func (*firstFailBindPlugin) Name() string {
|
||||||
return "firstFailBindPlugin"
|
return "firstFailBindPlugin"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user