AwaitReachable tries to make a TCP connection to addr regularly. It returns an error if it's unable to make a connection before maxWait.
(addr string, maxWait time.Duration)
| 28 | // AwaitReachable tries to make a TCP connection to addr regularly. |
| 29 | // It returns an error if it's unable to make a connection before maxWait. |
| 30 | func AwaitReachable(addr string, maxWait time.Duration) error { |
| 31 | done := time.Now().Add(maxWait) |
| 32 | for time.Now().Before(done) { |
| 33 | c, err := net.Dial("tcp", addr) |
| 34 | if err == nil { |
| 35 | c.Close() |
| 36 | return nil |
| 37 | } |
| 38 | time.Sleep(100 * time.Millisecond) |
| 39 | } |
| 40 | return fmt.Errorf("%v unreachable for %v", addr, maxWait) |
| 41 | } |
| 42 | |
| 43 | // HostPort takes a urlStr string URL, and returns a host:port string suitable |
| 44 | // to passing to net.Dial, with the port set as the scheme's default port if |
no test coverage detected