From 519b57484cbc02f3588f2e3d1c67b3cfade191d8 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Mon, 18 Jul 2016 11:22:50 -0700 Subject: [PATCH] wait for the podInformer to observe the pod creation in the rc's TestAdoption test --- .../integration/replicationcontroller_test.go | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/integration/replicationcontroller_test.go b/test/integration/replicationcontroller_test.go index 81f0c622049..45e8265665f 100644 --- a/test/integration/replicationcontroller_test.go +++ b/test/integration/replicationcontroller_test.go @@ -216,7 +216,8 @@ func TestAdoption(t *testing.T) { if err != nil { t.Fatalf("Failed to create replication controller: %v", err) } - pod := newMatchingPod("pod1", ns.Name) + podName := fmt.Sprintf("pod%d", i) + pod := newMatchingPod(podName, ns.Name) pod.OwnerReferences = tc.existingOwnerReferences(rc) _, err = podClient.Create(pod) if err != nil { @@ -225,6 +226,23 @@ func TestAdoption(t *testing.T) { stopCh := make(chan struct{}) go podInformer.Run(stopCh) + // wait for the podInformer to observe the pod, otherwise the rc manager + // will try to create a new pod rather than adopting the existing one. + if err := wait.Poll(10*time.Second, 60*time.Second, func() (bool, error) { + objects := podInformer.GetIndexer().List() + for _, object := range objects { + pod, ok := object.(*api.Pod) + if !ok { + t.Fatal("expect object to be a pod") + } + if pod.Name == podName { + return true, nil + } + } + return false, nil + }); err != nil { + t.Fatal(err) + } go rm.Run(5, stopCh) if err := wait.Poll(10*time.Second, 60*time.Second, func() (bool, error) { updatedPod, err := podClient.Get(pod.Name)