Skip to content

Commit 1c93be2

Browse files
authored
Merge pull request kubernetes#93629 from cofyc/93009
fix flaky TestVolumeBinding unit test
2 parents ba10448 + 96d0408 commit 1c93be2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ func TestVolumeBinding(t *testing.T) {
252252
t.Fatal(err)
253253
}
254254

255-
// Start informer factory after initialization
256-
informerFactory.Start(ctx.Done())
257-
258-
// Feed testing data and wait for them to be synced
255+
t.Log("Feed testing data and wait for them to be synced")
259256
client.StorageV1().StorageClasses().Create(ctx, immediateSC, metav1.CreateOptions{})
260257
client.StorageV1().StorageClasses().Create(ctx, waitSC, metav1.CreateOptions{})
261258
if item.node != nil {
@@ -267,19 +264,21 @@ func TestVolumeBinding(t *testing.T) {
267264
for _, pv := range item.pvs {
268265
client.CoreV1().PersistentVolumes().Create(ctx, pv, metav1.CreateOptions{})
269266
}
270-
caches := informerFactory.WaitForCacheSync(ctx.Done())
271-
for _, synced := range caches {
272-
if !synced {
273-
t.Errorf("error waiting for informer cache sync")
274-
}
275-
}
276267

277-
// Verify
268+
t.Log("Start informer factory after initialization")
269+
informerFactory.Start(ctx.Done())
270+
271+
t.Log("Wait for all started informers' cache were synced")
272+
informerFactory.WaitForCacheSync(ctx.Done())
273+
274+
t.Log("Verify")
275+
278276
p := pl.(*VolumeBinding)
279277
nodeInfo := framework.NewNodeInfo()
280278
nodeInfo.SetNode(item.node)
281279
state := framework.NewCycleState()
282-
t.Logf("call PreFilter and check status")
280+
281+
t.Logf("Verify: call PreFilter and check status")
283282
gotPreFilterStatus := p.PreFilter(ctx, state, item.pod)
284283
if !reflect.DeepEqual(gotPreFilterStatus, item.wantPreFilterStatus) {
285284
t.Errorf("filter prefilter status does not match: %v, want: %v", gotPreFilterStatus, item.wantPreFilterStatus)
@@ -288,15 +287,17 @@ func TestVolumeBinding(t *testing.T) {
288287
// scheduler framework will skip Filter if PreFilter fails
289288
return
290289
}
291-
t.Logf("check state after prefilter phase")
290+
291+
t.Logf("Verify: check state after prefilter phase")
292292
stateData, err := getStateData(state)
293293
if err != nil {
294294
t.Fatal(err)
295295
}
296296
if !reflect.DeepEqual(stateData, item.wantStateAfterPreFilter) {
297297
t.Errorf("state got after prefilter does not match: %v, want: %v", stateData, item.wantStateAfterPreFilter)
298298
}
299-
t.Logf("call Filter and check status")
299+
300+
t.Logf("Verify: call Filter and check status")
300301
gotStatus := p.Filter(ctx, state, item.pod, nodeInfo)
301302
if !reflect.DeepEqual(gotStatus, item.wantFilterStatus) {
302303
t.Errorf("filter status does not match: %v, want: %v", gotStatus, item.wantFilterStatus)

0 commit comments

Comments
 (0)