From b6b7ab3f731225e2c086048cbcac5ec3ee542264 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Mon, 3 Aug 2020 12:28:25 -0700 Subject: [PATCH] Deflake scheduler PostBind integration test --- test/integration/scheduler/framework_test.go | 88 +++++++++++--------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/test/integration/scheduler/framework_test.go b/test/integration/scheduler/framework_test.go index 9657f035fd8..3996123c195 100644 --- a/test/integration/scheduler/framework_test.go +++ b/test/integration/scheduler/framework_test.go @@ -1262,45 +1262,9 @@ func TestBindPlugin(t *testing.T) { // TestPostBindPlugin tests invocation of postbind plugins. func TestPostBindPlugin(t *testing.T) { - // Create a plugin registry for testing. Register a prebind and a postbind plugin. - preBindPlugin := &PreBindPlugin{} - postBindPlugin := &PostBindPlugin{name: postBindPluginName} - registry := frameworkruntime.Registry{ - preBindPluginName: newPlugin(preBindPlugin), - postBindPluginName: newPlugin(postBindPlugin), - } - - // Setup initial prebind and postbind plugin for testing. - prof := schedulerconfig.KubeSchedulerProfile{ - SchedulerName: v1.DefaultSchedulerName, - Plugins: &schedulerconfig.Plugins{ - PreBind: &schedulerconfig.PluginSet{ - Enabled: []schedulerconfig.Plugin{ - { - Name: preBindPluginName, - }, - }, - }, - PostBind: &schedulerconfig.PluginSet{ - Enabled: []schedulerconfig.Plugin{ - { - Name: postBindPluginName, - }, - }, - }, - }, - } - - // Create the master and the scheduler with the test plugin set. - testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "postbind-plugin", nil), 2, - scheduler.WithProfiles(prof), - scheduler.WithFrameworkOutOfTreeRegistry(registry)) - defer testutils.CleanupTest(t, testCtx) - tests := []struct { - name string - preBindFail bool - preBindReject bool + name string + preBindFail bool }{ { name: "plugin preBind fail", @@ -1314,7 +1278,46 @@ func TestPostBindPlugin(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - preBindPlugin.failPreBind = test.preBindFail + // Create a plugin registry for testing. Register a prebind and a postbind plugin. + preBindPlugin := &PreBindPlugin{ + failPreBind: test.preBindFail, + } + postBindPlugin := &PostBindPlugin{ + name: postBindPluginName, + pluginInvokeEventChan: make(chan pluginInvokeEvent, 1), + } + registry := frameworkruntime.Registry{ + preBindPluginName: newPlugin(preBindPlugin), + postBindPluginName: newPlugin(postBindPlugin), + } + + // Setup initial prebind and postbind plugin for testing. + prof := schedulerconfig.KubeSchedulerProfile{ + SchedulerName: v1.DefaultSchedulerName, + Plugins: &schedulerconfig.Plugins{ + PreBind: &schedulerconfig.PluginSet{ + Enabled: []schedulerconfig.Plugin{ + { + Name: preBindPluginName, + }, + }, + }, + PostBind: &schedulerconfig.PluginSet{ + Enabled: []schedulerconfig.Plugin{ + { + Name: postBindPluginName, + }, + }, + }, + }, + } + + // Create the master and the scheduler with the test plugin set. + testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "postbind-plugin", nil), 2, + scheduler.WithProfiles(prof), + scheduler.WithFrameworkOutOfTreeRegistry(registry)) + defer testutils.CleanupTest(t, testCtx) + // Create a best effort pod. pod, err := createPausePod(testCtx.ClientSet, initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name})) @@ -1333,13 +1336,16 @@ func TestPostBindPlugin(t *testing.T) { if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } + select { + case <-postBindPlugin.pluginInvokeEventChan: + case <-time.After(time.Second * 15): + t.Errorf("pluginInvokeEventChan timed out") + } if postBindPlugin.numPostBindCalled == 0 { 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}) }) }