From 1a6c36da537087fa26b3719ca4d429cb9955b155 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Tue, 14 Mar 2017 14:31:37 -0400 Subject: [PATCH] Fix dswp flake - from pod not showing in dswp Sometimes a pod may not appear in desired state of world immediately, we poll before failing. It only adds additional 30s to tests in worst case. --- test/integration/volume/attach_detach_test.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/integration/volume/attach_detach_test.go b/test/integration/volume/attach_detach_test.go index 42ae3d5a146..d17dab52372 100644 --- a/test/integration/volume/attach_detach_test.go +++ b/test/integration/volume/attach_detach_test.go @@ -33,6 +33,7 @@ import ( informers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions" fakecloud "k8s.io/kubernetes/pkg/cloudprovider/providers/fake" "k8s.io/kubernetes/pkg/controller/volume/attachdetach" + volumecache "k8s.io/kubernetes/pkg/controller/volume/attachdetach/cache" "k8s.io/kubernetes/pkg/volume" volumetest "k8s.io/kubernetes/pkg/volume/testing" "k8s.io/kubernetes/pkg/volume/util/volumehelper" @@ -128,11 +129,7 @@ func TestPodDeletionWithDswp(t *testing.T) { t.Fatalf("Pod not found in Pod Informer cache : %v", err) } - podsToAdd := ctrl.GetDesiredStateOfWorld().GetPodToAdd() - - if len(podsToAdd) == 0 { - t.Fatalf("Pod not added to desired state of world") - } + waitForPodsInDSWP(t, ctrl.GetDesiredStateOfWorld()) // let's stop pod events from getting triggered close(podStopCh) @@ -144,7 +141,7 @@ func TestPodDeletionWithDswp(t *testing.T) { waitToObservePods(t, podInformer, 0) // the populator loop turns every 1 minute time.Sleep(80 * time.Second) - podsToAdd = ctrl.GetDesiredStateOfWorld().GetPodToAdd() + podsToAdd := ctrl.GetDesiredStateOfWorld().GetPodToAdd() if len(podsToAdd) != 0 { t.Fatalf("All pods should have been removed") } @@ -168,6 +165,19 @@ func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podN } } +// wait for pods to be observed in desired state of world +func waitForPodsInDSWP(t *testing.T, dswp volumecache.DesiredStateOfWorld) { + if err := wait.Poll(time.Millisecond*500, wait.ForeverTestTimeout, func() (bool, error) { + pods := dswp.GetPodToAdd() + if len(pods) > 0 { + return true, nil + } + return false, nil + }); err != nil { + t.Fatalf("Pod not added to desired state of world : %v", err) + } +} + func createAdClients(ns *v1.Namespace, t *testing.T, server *httptest.Server, syncPeriod time.Duration) (*clientset.Clientset, attachdetach.AttachDetachController, informers.SharedInformerFactory) { config := restclient.Config{ Host: server.URL,