@@ -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