Merge pull request #10339 from marekbiskup/timeout-messages

add description to timeout messages
This commit is contained in:
Alex Robinson 2015-06-29 11:01:38 -07:00
commit 85b590413d
3 changed files with 28 additions and 14 deletions

View File

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

View File

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

View File

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