Add retry logic to events e2e test.

This commit is contained in:
Quinton Hoole 2015-05-12 15:47:58 -07:00
parent 0b0bace006
commit 0981179d63

View File

@ -26,6 +26,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields" "github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -87,39 +88,48 @@ var _ = Describe("Events", func() {
Failf("Failed to get pod: %v", err) Failf("Failed to get pod: %v", err)
} }
fmt.Printf("%+v\n", podWithUid) fmt.Printf("%+v\n", podWithUid)
var events *api.EventList
// Check for scheduler event about the pod. // Check for scheduler event about the pod.
By("checking for scheduler event about the pod") By("checking for scheduler event about the pod")
events, err := c.Events(api.NamespaceDefault).List( expectNoError(wait.Poll(time.Second*2, time.Second*60, func() (bool, error) {
labels.Everything(), events, err := c.Events(api.NamespaceDefault).List(
fields.Set{ labels.Everything(),
"involvedObject.kind": "Pod", fields.Set{
"involvedObject.uid": string(podWithUid.UID), "involvedObject.kind": "Pod",
"involvedObject.namespace": api.NamespaceDefault, "involvedObject.uid": string(podWithUid.UID),
"source": "scheduler", "involvedObject.namespace": api.NamespaceDefault,
}.AsSelector(), "source": "scheduler",
) }.AsSelector(),
if err != nil { )
Failf("Error while listing events: %v", err) if err != nil {
} return false, err
Expect(len(events.Items)).ToNot(BeZero(), "scheduler events from running pod") }
fmt.Println("Saw scheduler event for our pod.") if len(events.Items) > 0 {
fmt.Println("Saw scheduler event for our pod.")
return true, nil
}
return false, nil
}))
// Check for kubelet event about the pod. // Check for kubelet event about the pod.
By("checking for kubelet event about the pod") By("checking for kubelet event about the pod")
events, err = c.Events(api.NamespaceDefault).List( expectNoError(wait.Poll(time.Second*2, time.Second*60, func() (bool, error) {
labels.Everything(), events, err = c.Events(api.NamespaceDefault).List(
fields.Set{ labels.Everything(),
"involvedObject.uid": string(podWithUid.UID), fields.Set{
"involvedObject.kind": "Pod", "involvedObject.uid": string(podWithUid.UID),
"involvedObject.namespace": api.NamespaceDefault, "involvedObject.kind": "Pod",
"source": "kubelet", "involvedObject.namespace": api.NamespaceDefault,
}.AsSelector(), "source": "kubelet",
) }.AsSelector(),
if err != nil { )
Failf("Error while listing events: %v", err) if err != nil {
} return false, err
Expect(len(events.Items)).ToNot(BeZero(), "kubelet events from running pod") }
fmt.Println("Saw kubelet event for our pod.") if len(events.Items) > 0 {
fmt.Println("Saw kubelet event for our pod.")
return true, nil
}
return false, nil
}))
}) })
}) })