Revert "improve e2e retry logic with standard wait.Poll()"

This commit is contained in:
Quinton Hoole
2015-05-19 11:17:32 -07:00
parent b963307496
commit 14665119b4
10 changed files with 119 additions and 123 deletions

View File

@@ -28,7 +28,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -83,7 +82,7 @@ var _ = Describe("Services", func() {
Expect(foundRO).To(Equal(true))
})
It("should serve a basic endpoint from pods", func() {
It("should serve a basic endpoint from pods", func(done Done) {
serviceName := "endpoint-test2"
ns := namespaces[0]
labels := map[string]string{
@@ -145,9 +144,13 @@ var _ = Describe("Services", func() {
validateEndpointsOrFail(c, ns, serviceName, map[string][]int{})
})
// We deferred Gingko pieces that may Fail, we aren't done.
defer func() {
close(done)
}()
}, 240.0)
It("should serve multiport endpoints from pods", func() {
It("should serve multiport endpoints from pods", func(done Done) {
// repacking functionality is intentionally not tested here - it's better to test it in an integration test.
serviceName := "multi-endpoint-test"
ns := namespaces[0]
@@ -242,7 +245,11 @@ var _ = Describe("Services", func() {
validateEndpointsOrFail(c, ns, serviceName, map[string][]int{})
})
// We deferred Gingko pieces that may Fail, we aren't done.
defer func() {
close(done)
}()
}, 240.0)
It("should be able to create a functioning external load balancer", func() {
if !providerIs("gce", "gke") {
@@ -321,13 +328,13 @@ var _ = Describe("Services", func() {
By("hitting the pod through the service's external load balancer")
var resp *http.Response
expectNoError(wait.Poll(5*time.Second, podStartTimeout, func() (bool, error) {
for t := time.Now(); time.Since(t) < podStartTimeout; time.Sleep(5 * time.Second) {
resp, err = http.Get(fmt.Sprintf("http://%s:%d", ip, port))
if err == nil {
return true, nil
break
}
return false, nil
}))
}
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
@@ -393,21 +400,16 @@ func waitForPublicIPs(c *client.Client, serviceName, namespace string) (*api.Ser
const timeout = 4 * time.Minute
var service *api.Service
By(fmt.Sprintf("waiting up to %v for service %s in namespace %s to have a public IP", timeout, serviceName, namespace))
start := time.Now()
expectNoError(wait.Poll(5*time.Second, timeout, func() (bool, error) {
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
service, err := c.Services(namespace).Get(serviceName)
if err != nil {
Logf("Get service failed, ignoring for 5s: %v", err)
return false, nil
continue
}
if len(service.Spec.PublicIPs) > 0 {
return true, nil
return service, nil
}
Logf("Waiting for service %s in namespace %s to have a public IP (%v)", serviceName, namespace, time.Since(start))
return false, nil
}))
if len(service.Spec.PublicIPs) > 0 {
return service, nil
}
return service, fmt.Errorf("service %s in namespace %s doesn't have a public IP after %.2f seconds", serviceName, namespace, timeout.Seconds())
}
@@ -479,28 +481,27 @@ func validatePortsOrFail(endpoints map[string][]int, expectedEndpoints map[strin
func validateEndpointsOrFail(c *client.Client, ns, serviceName string, expectedEndpoints map[string][]int) {
By(fmt.Sprintf("Validating endpoints %v with on service %s/%s", expectedEndpoints, ns, serviceName))
expectNoError(wait.Poll(time.Second, 120*time.Second, func() (bool, error) {
for {
endpoints, err := c.Endpoints(ns).Get(serviceName)
if err == nil {
Logf("Found endpoints %v", endpoints)
By(fmt.Sprintf("Found endpoints %v", endpoints))
portsByIp := getPortsByIp(endpoints.Subsets)
Logf("Found ports by ip %v", portsByIp)
By(fmt.Sprintf("Found ports by ip %v", portsByIp))
if len(portsByIp) == len(expectedEndpoints) {
expectedPortsByIp := translatePodNameToIpOrFail(c, ns, expectedEndpoints)
validatePortsOrFail(portsByIp, expectedPortsByIp)
return true, nil
break
} else {
Logf("Unexpected number of endpoints: found %v, expected %v (ignoring for 1 second)", portsByIp, expectedEndpoints)
By(fmt.Sprintf("Unexpected number of endpoints: found %v, expected %v (ignoring for 1 second)", portsByIp, expectedEndpoints))
}
} else {
Logf("Failed to get endpoints: %v (ignoring for 1 second)", err)
By(fmt.Sprintf("Failed to get endpoints: %v (ignoring for 1 second)", err))
}
return false, nil
}))
Logf("successfully validated endpoints %v with on service %s/%s", expectedEndpoints, ns, serviceName)
time.Sleep(time.Second)
}
By(fmt.Sprintf("successfully validated endpoints %v with on service %s/%s", expectedEndpoints, ns, serviceName))
}
func addEndpointPodOrFail(c *client.Client, ns, name string, labels map[string]string, containerPorts []api.ContainerPort) {