Skip to content

Commit 78226e0

Browse files
authored
fix: scheduler flaky test (#1402)
* fix flaking test Signed-off-by: Jifei Wang <[email protected]> * resolve comment Signed-off-by: Jifei Wang <[email protected]> --------- Signed-off-by: Jifei Wang <[email protected]>
1 parent 8fbec81 commit 78226e0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/scheduler/scheduler_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
corev1 "k8s.io/api/core/v1"
2828
"k8s.io/apimachinery/pkg/api/resource"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/apimachinery/pkg/util/wait"
3031
"k8s.io/client-go/informers"
3132
"k8s.io/client-go/kubernetes/fake"
3233
"k8s.io/client-go/tools/cache"
@@ -1126,6 +1127,14 @@ func Test_ResourceQuota(t *testing.T) {
11261127
client.KubeClient.CoreV1().Pods(test.args.Pod.Namespace).Create(context.Background(), test.args.Pod, metav1.CreateOptions{})
11271128
got, gotErr := s.Filter(test.args)
11281129
client.KubeClient.CoreV1().Pods(test.args.Pod.Namespace).Delete(context.Background(), test.args.Pod.Name, metav1.DeleteOptions{})
1130+
// wait for pod deletion to be processed by the informer
1131+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1132+
defer cancel()
1133+
err := wait.PollUntilContextTimeout(ctx, 10*time.Millisecond, 2*time.Second, true, func(ctx context.Context) (bool, error) {
1134+
_, ok := s.podManager.GetPod(test.args.Pod)
1135+
return !ok, nil
1136+
})
1137+
require.NoError(t, err, "timed out waiting for pod to be deleted from pod manager")
11291138
s.onDelQuota(&test.quota)
11301139
assert.DeepEqual(t, test.wantErr, gotErr)
11311140
assert.DeepEqual(t, test.want, got)

0 commit comments

Comments
 (0)