From 955cd34404f1259cd240a425d8f08f4cedf6f28c Mon Sep 17 00:00:00 2001 From: mpl Date: Wed, 16 Jul 2014 20:05:52 +0200 Subject: [PATCH] dockertest: skip test when DB in container not ready http://camlistore.org/issue/474 Change-Id: Id65b3c35a2f38466c4d7370bad4c5f73a8cb22db --- pkg/netutil/netutil.go | 4 ++-- pkg/test/dockertest/docker.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/netutil/netutil.go b/pkg/netutil/netutil.go index 5916ff7fb..99b0c5b7f 100644 --- a/pkg/netutil/netutil.go +++ b/pkg/netutil/netutil.go @@ -17,7 +17,7 @@ limitations under the License. package netutil import ( - "errors" + "fmt" "net" "time" ) @@ -34,5 +34,5 @@ func AwaitReachable(addr string, maxWait time.Duration) error { } time.Sleep(100 * time.Millisecond) } - return errors.New("timeout") + return fmt.Errorf("%v unreachable for %v", addr, maxWait) } diff --git a/pkg/test/dockertest/docker.go b/pkg/test/dockertest/docker.go index 4661563ce..bfc464021 100644 --- a/pkg/test/dockertest/docker.go +++ b/pkg/test/dockertest/docker.go @@ -118,7 +118,7 @@ func IP(containerID string) (string, error) { if ip := c[0].NetworkSettings.IPAddress; ip != "" { return ip, nil } - return "", fmt.Errorf("could not find an IP for %v. Not running?", containerID) + return "", errors.New("could not find an IP. Not running?") } type ContainerID string @@ -153,13 +153,11 @@ func (c ContainerID) KillRemove(t *testing.T) { func (c ContainerID) lookup(port int, timeout time.Duration) (ip string, err error) { ip, err = c.IP() if err != nil { - err = fmt.Errorf("Error getting container IP: %v", err) + err = fmt.Errorf("error getting IP: %v", err) return } addr := fmt.Sprintf("%s:%d", ip, port) - if err = netutil.AwaitReachable(addr, timeout); err != nil { - err = fmt.Errorf("timeout trying to reach %s for container %v: %v", addr, c, err) - } + err = netutil.AwaitReachable(addr, timeout) return } @@ -179,7 +177,7 @@ func setupContainer(t *testing.T, image string, port int, timeout time.Duration, ip, err = c.lookup(port, timeout) if err != nil { c.KillRemove(t) - t.Fatalf("container lookup: %v", err) + t.Skipf("Skipping test for container %v: %v", c, err) } return }