dockertest: skip test when DB in container not ready

http://camlistore.org/issue/474

Change-Id: Id65b3c35a2f38466c4d7370bad4c5f73a8cb22db
This commit is contained in:
mpl 2014-07-16 20:05:52 +02:00
parent e9de15d596
commit 955cd34404
2 changed files with 6 additions and 8 deletions

View File

@ -17,7 +17,7 @@ limitations under the License.
package netutil package netutil
import ( import (
"errors" "fmt"
"net" "net"
"time" "time"
) )
@ -34,5 +34,5 @@ func AwaitReachable(addr string, maxWait time.Duration) error {
} }
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }
return errors.New("timeout") return fmt.Errorf("%v unreachable for %v", addr, maxWait)
} }

View File

@ -118,7 +118,7 @@ func IP(containerID string) (string, error) {
if ip := c[0].NetworkSettings.IPAddress; ip != "" { if ip := c[0].NetworkSettings.IPAddress; ip != "" {
return ip, nil 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 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) { func (c ContainerID) lookup(port int, timeout time.Duration) (ip string, err error) {
ip, err = c.IP() ip, err = c.IP()
if err != nil { if err != nil {
err = fmt.Errorf("Error getting container IP: %v", err) err = fmt.Errorf("error getting IP: %v", err)
return return
} }
addr := fmt.Sprintf("%s:%d", ip, port) addr := fmt.Sprintf("%s:%d", ip, port)
if err = netutil.AwaitReachable(addr, timeout); err != nil { err = netutil.AwaitReachable(addr, timeout)
err = fmt.Errorf("timeout trying to reach %s for container %v: %v", addr, c, err)
}
return return
} }
@ -179,7 +177,7 @@ func setupContainer(t *testing.T, image string, port int, timeout time.Duration,
ip, err = c.lookup(port, timeout) ip, err = c.lookup(port, timeout)
if err != nil { if err != nil {
c.KillRemove(t) c.KillRemove(t)
t.Fatalf("container lookup: %v", err) t.Skipf("Skipping test for container %v: %v", c, err)
} }
return return
} }