From 4b3078fe9aeb68046db28c9cd65c0976b903ee00 Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Thu, 3 Jan 2019 11:45:29 -0800 Subject: [PATCH] Fix flaking evictions test --- test/integration/evictions/evictions_test.go | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/integration/evictions/evictions_test.go b/test/integration/evictions/evictions_test.go index 6354c2b5d85..640e285da52 100644 --- a/test/integration/evictions/evictions_test.go +++ b/test/integration/evictions/evictions_test.go @@ -86,7 +86,7 @@ func TestConcurrentEvictionRequests(t *testing.T) { } } - waitToObservePods(t, informers.Core().V1().Pods().Informer(), numOfEvictions) + waitToObservePods(t, informers.Core().V1().Pods().Informer(), numOfEvictions, v1.PodRunning) pdb := newPDB() if _, err := clientSet.Policy().PodDisruptionBudgets(ns.Name).Create(pdb); err != nil { @@ -193,18 +193,21 @@ func TestTerminalPodEviction(t *testing.T) { if _, err := clientSet.CoreV1().Pods(ns.Name).Create(pod); err != nil { t.Errorf("Failed to create pod: %v", err) } + addPodConditionSucceeded(pod) if _, err := clientSet.CoreV1().Pods(ns.Name).UpdateStatus(pod); err != nil { t.Fatal(err) } - waitToObservePods(t, informers.Core().V1().Pods().Informer(), 1) + waitToObservePods(t, informers.Core().V1().Pods().Informer(), 1, v1.PodSucceeded) pdb := newPDB() if _, err := clientSet.Policy().PodDisruptionBudgets(ns.Name).Create(pdb); err != nil { t.Errorf("Failed to create PodDisruptionBudget: %v", err) } + waitPDBStable(t, clientSet, 1, ns.Name, pdb.Name) + pdbList, err := clientSet.Policy().PodDisruptionBudgets(ns.Name).List(metav1.ListOptions{}) if err != nil { t.Fatalf("Error while listing pod disruption budget") @@ -341,13 +344,19 @@ func rmSetup(t *testing.T) (*httptest.Server, framework.CloseFunc, *disruption.D // wait for the podInformer to observe the pods. Call this function before // running the RS controller to prevent the rc manager from creating new pods // rather than adopting the existing ones. -func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podNum int) { +func waitToObservePods(t *testing.T, podInformer cache.SharedIndexInformer, podNum int, phase v1.PodPhase) { if err := wait.PollImmediate(2*time.Second, 60*time.Second, func() (bool, error) { objects := podInformer.GetIndexer().List() - if len(objects) == podNum { - return true, nil + if len(objects) != podNum { + return false, nil } - return false, nil + for _, obj := range objects { + pod := obj.(*v1.Pod) + if pod.Status.Phase != phase { + return false, nil + } + } + return true, nil }); err != nil { t.Fatal(err) }