From 01e1d3710a205738564e8255215219e8497405dc Mon Sep 17 00:00:00 2001 From: Marek Biskup Date: Thu, 25 Jun 2015 09:51:38 +0200 Subject: [PATCH] add description to timeout messages --- test/e2e/resize_nodes.go | 4 ++-- test/e2e/service.go | 18 +++++++++++------- test/e2e/util.go | 20 +++++++++++++++----- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/test/e2e/resize_nodes.go b/test/e2e/resize_nodes.go index 39595925582..4962e214763 100644 --- a/test/e2e/resize_nodes.go +++ b/test/e2e/resize_nodes.go @@ -294,11 +294,11 @@ func verifyPods(c *client.Client, ns, name string, wantName bool, replicas int) } e := podsRunning(c, pods) if len(e) > 0 { - return fmt.Errorf("Failed to wait for pods running: %v", e) + return fmt.Errorf("failed to wait for pods running: %v", e) } err = podsResponding(c, ns, name, wantName, pods) if err != nil { - return err + return fmt.Errorf("failed to wait for pods responding: %v", err) } return nil } diff --git a/test/e2e/service.go b/test/e2e/service.go index b4d292e0f11..cfe061796bf 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -1004,9 +1004,10 @@ func testReachable(ip string, port int) { Failf("Got port==0 for reachability check (%s)", url) } - By(fmt.Sprintf("Waiting up to %v for %s to be reachable", podStartTimeout, url)) + desc := fmt.Sprintf("the url %s to be reachable", url) + By(fmt.Sprintf("Waiting up to %v for %s", podStartTimeout, desc)) start := time.Now() - expectNoError(wait.Poll(poll, podStartTimeout, func() (bool, error) { + err := wait.Poll(poll, podStartTimeout, func() (bool, error) { resp, err := httpGetNoConnectionPool(url) if err != nil { Logf("Got error waiting for reachability of %s: %v (%v)", url, err, time.Since(start)) @@ -1026,7 +1027,8 @@ func testReachable(ip string, port int) { } Logf("Successfully reached %v", url) return true, nil - })) + }) + Expect(err).NotTo(HaveOccurred(), "Error waiting for %s", desc) } func testNotReachable(ip string, port int) { @@ -1038,11 +1040,12 @@ func testNotReachable(ip string, port int) { Failf("Got port==0 for non-reachability check (%s)", url) } - By(fmt.Sprintf("Waiting up to %v for %s to be *not* reachable", podStartTimeout, url)) - expectNoError(wait.Poll(poll, podStartTimeout, func() (bool, error) { + desc := fmt.Sprintf("the url %s to be *not* reachable", url) + By(fmt.Sprintf("Waiting up to %v for %s", podStartTimeout, desc)) + err := wait.Poll(poll, podStartTimeout, func() (bool, error) { resp, err := httpGetNoConnectionPool(url) if err != nil { - Logf("Successfully waited for the url %s to be unreachable.", url) + Logf("Successfully waited for %s", desc) return true, nil } defer resp.Body.Close() @@ -1053,7 +1056,8 @@ func testNotReachable(ip string, port int) { } Logf("Able to reach service %s when should no longer have been reachable, status:%d and body: %s", url, resp.Status, string(body)) return false, nil - })) + }) + Expect(err).NotTo(HaveOccurred(), "Error waiting for %s", desc) } // Does an HTTP GET, but does not reuse TCP connections diff --git a/test/e2e/util.go b/test/e2e/util.go index e8260ab1c58..8b3514d614c 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -515,7 +515,7 @@ func waitForRCPodOnNode(c *client.Client, ns, rcName, node string) (*api.Pod, er return p, err } -// waitForRCPodOnNode returns nil if the pod from the given replication controller (decribed by rcName) no longer exists. +// waitForRCPodToDisappear returns nil if the pod from the given replication controller (decribed by rcName) no longer exists. // In case of failure or too long waiting time, an error is returned. func waitForRCPodToDisappear(c *client.Client, ns, rcName, podName string) error { label := labels.SelectorFromSet(labels.Set(map[string]string{"name": rcName})) @@ -540,9 +540,9 @@ func waitForRCPodToDisappear(c *client.Client, ns, rcName, podName string) error }) } -// waits until the service appears (exists == true), or disappears (exists == false) +// waitForService waits until the service appears (exist == true), or disappears (exist == false) func waitForService(c *client.Client, namespace, name string, exist bool, interval, timeout time.Duration) error { - return wait.Poll(interval, timeout, func() (bool, error) { + err := wait.Poll(interval, timeout, func() (bool, error) { _, err := c.Services(namespace).Get(name) if err != nil { Logf("Get service %s in namespace %s failed (%v).", name, namespace, err) @@ -552,11 +552,16 @@ func waitForService(c *client.Client, namespace, name string, exist bool, interv return exist, nil } }) + if err != nil { + stateMsg := map[bool]string{true: "to appear", false: "to disappear"} + return fmt.Errorf("error waiting for service %s/%s %s: %v", namespace, name, stateMsg[exist], err) + } + return nil } -// waits until the RC appears (exists == true), or disappears (exists == false) +// waitForReplicationController waits until the RC appears (exist == true), or disappears (exist == false) func waitForReplicationController(c *client.Client, namespace, name string, exist bool, interval, timeout time.Duration) error { - return wait.Poll(interval, timeout, func() (bool, error) { + err := wait.Poll(interval, timeout, func() (bool, error) { _, err := c.ReplicationControllers(namespace).Get(name) if err != nil { Logf("Get ReplicationController %s in namespace %s failed (%v).", name, namespace, err) @@ -566,6 +571,11 @@ func waitForReplicationController(c *client.Client, namespace, name string, exis return exist, nil } }) + if err != nil { + stateMsg := map[bool]string{true: "to appear", false: "to disappear"} + return fmt.Errorf("error waiting for ReplicationController %s/%s %s: %v", namespace, name, stateMsg[exist], err) + } + return nil } // Context for checking pods responses by issuing GETs to them and verifying if the answer with pod name.