Skip to content

Commit c73fef5

Browse files
authored
Merge pull request kubernetes#93661 from Huang-Wei/flake-postbind
Deflake scheduler PostBind integration test
2 parents c381615 + b6b7ab3 commit c73fef5

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,45 +1262,9 @@ func TestBindPlugin(t *testing.T) {
12621262

12631263
// TestPostBindPlugin tests invocation of postbind plugins.
12641264
func TestPostBindPlugin(t *testing.T) {
1265-
// Create a plugin registry for testing. Register a prebind and a postbind plugin.
1266-
preBindPlugin := &PreBindPlugin{}
1267-
postBindPlugin := &PostBindPlugin{name: postBindPluginName}
1268-
registry := frameworkruntime.Registry{
1269-
preBindPluginName: newPlugin(preBindPlugin),
1270-
postBindPluginName: newPlugin(postBindPlugin),
1271-
}
1272-
1273-
// Setup initial prebind and postbind plugin for testing.
1274-
prof := schedulerconfig.KubeSchedulerProfile{
1275-
SchedulerName: v1.DefaultSchedulerName,
1276-
Plugins: &schedulerconfig.Plugins{
1277-
PreBind: &schedulerconfig.PluginSet{
1278-
Enabled: []schedulerconfig.Plugin{
1279-
{
1280-
Name: preBindPluginName,
1281-
},
1282-
},
1283-
},
1284-
PostBind: &schedulerconfig.PluginSet{
1285-
Enabled: []schedulerconfig.Plugin{
1286-
{
1287-
Name: postBindPluginName,
1288-
},
1289-
},
1290-
},
1291-
},
1292-
}
1293-
1294-
// Create the master and the scheduler with the test plugin set.
1295-
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "postbind-plugin", nil), 2,
1296-
scheduler.WithProfiles(prof),
1297-
scheduler.WithFrameworkOutOfTreeRegistry(registry))
1298-
defer testutils.CleanupTest(t, testCtx)
1299-
13001265
tests := []struct {
1301-
name string
1302-
preBindFail bool
1303-
preBindReject bool
1266+
name string
1267+
preBindFail bool
13041268
}{
13051269
{
13061270
name: "plugin preBind fail",
@@ -1314,7 +1278,46 @@ func TestPostBindPlugin(t *testing.T) {
13141278

13151279
for _, test := range tests {
13161280
t.Run(test.name, func(t *testing.T) {
1317-
preBindPlugin.failPreBind = test.preBindFail
1281+
// Create a plugin registry for testing. Register a prebind and a postbind plugin.
1282+
preBindPlugin := &PreBindPlugin{
1283+
failPreBind: test.preBindFail,
1284+
}
1285+
postBindPlugin := &PostBindPlugin{
1286+
name: postBindPluginName,
1287+
pluginInvokeEventChan: make(chan pluginInvokeEvent, 1),
1288+
}
1289+
registry := frameworkruntime.Registry{
1290+
preBindPluginName: newPlugin(preBindPlugin),
1291+
postBindPluginName: newPlugin(postBindPlugin),
1292+
}
1293+
1294+
// Setup initial prebind and postbind plugin for testing.
1295+
prof := schedulerconfig.KubeSchedulerProfile{
1296+
SchedulerName: v1.DefaultSchedulerName,
1297+
Plugins: &schedulerconfig.Plugins{
1298+
PreBind: &schedulerconfig.PluginSet{
1299+
Enabled: []schedulerconfig.Plugin{
1300+
{
1301+
Name: preBindPluginName,
1302+
},
1303+
},
1304+
},
1305+
PostBind: &schedulerconfig.PluginSet{
1306+
Enabled: []schedulerconfig.Plugin{
1307+
{
1308+
Name: postBindPluginName,
1309+
},
1310+
},
1311+
},
1312+
},
1313+
}
1314+
1315+
// Create the master and the scheduler with the test plugin set.
1316+
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "postbind-plugin", nil), 2,
1317+
scheduler.WithProfiles(prof),
1318+
scheduler.WithFrameworkOutOfTreeRegistry(registry))
1319+
defer testutils.CleanupTest(t, testCtx)
1320+
13181321
// Create a best effort pod.
13191322
pod, err := createPausePod(testCtx.ClientSet,
13201323
initPausePod(&pausePodConfig{Name: "test-pod", Namespace: testCtx.NS.Name}))
@@ -1333,13 +1336,16 @@ func TestPostBindPlugin(t *testing.T) {
13331336
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
13341337
t.Errorf("Expected the pod to be scheduled. error: %v", err)
13351338
}
1339+
select {
1340+
case <-postBindPlugin.pluginInvokeEventChan:
1341+
case <-time.After(time.Second * 15):
1342+
t.Errorf("pluginInvokeEventChan timed out")
1343+
}
13361344
if postBindPlugin.numPostBindCalled == 0 {
13371345
t.Errorf("Expected the postbind plugin to be called, was called %d times.", postBindPlugin.numPostBindCalled)
13381346
}
13391347
}
13401348

1341-
postBindPlugin.reset()
1342-
preBindPlugin.reset()
13431349
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{pod})
13441350
})
13451351
}

0 commit comments

Comments
 (0)