Deflake scheduler PostBind integration test

This commit is contained in:
Wei Huang 2020-08-03 12:28:25 -07:00
parent e4472ca486
commit b6b7ab3f73
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005

View File

@ -1262,9 +1262,30 @@ func TestBindPlugin(t *testing.T) {
// TestPostBindPlugin tests invocation of postbind plugins.
func TestPostBindPlugin(t *testing.T) {
tests := []struct {
name string
preBindFail bool
}{
{
name: "plugin preBind fail",
preBindFail: true,
},
{
name: "plugin preBind do not fail",
preBindFail: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// Create a plugin registry for testing. Register a prebind and a postbind plugin.
preBindPlugin := &PreBindPlugin{}
postBindPlugin := &PostBindPlugin{name: postBindPluginName}
preBindPlugin := &PreBindPlugin{
failPreBind: test.preBindFail,
}
postBindPlugin := &PostBindPlugin{
name: postBindPluginName,
pluginInvokeEventChan: make(chan pluginInvokeEvent, 1),
}
registry := frameworkruntime.Registry{
preBindPluginName: newPlugin(preBindPlugin),
postBindPluginName: newPlugin(postBindPlugin),
@ -1297,24 +1318,6 @@ func TestPostBindPlugin(t *testing.T) {
scheduler.WithFrameworkOutOfTreeRegistry(registry))
defer testutils.CleanupTest(t, testCtx)
tests := []struct {
name string
preBindFail bool
preBindReject bool
}{
{
name: "plugin preBind fail",
preBindFail: true,
},
{
name: "plugin preBind do not fail",
preBindFail: false,
},
}
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}))
@ -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})
})
}