wait for the podInformer to observe the pod creation in the rc's TestAdoption test

This commit is contained in:
Chao Xu 2016-07-18 11:22:50 -07:00
parent 6d09ba41e9
commit 519b57484c

View File

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