(bindAddr string, port int, excludeAllocated bool)
| 48 | } |
| 49 | |
| 50 | func testPort(bindAddr string, port int, excludeAllocated bool) bool { |
| 51 | addr := net.JoinHostPort(bindAddr, fmt.Sprint(port)) |
| 52 | |
| 53 | if excludeAllocated { |
| 54 | if _, ok := allocatedPorts.Load(addr); ok { |
| 55 | return false |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | ln, err := net.Listen("tcp", addr) |
| 60 | if err != nil { |
| 61 | return false |
| 62 | } |
| 63 | ln.Close() |
| 64 | return true |
| 65 | } |
| 66 | |
| 67 | // WaitToConnect returns only when port is ready to connect or canceled by context. |
| 68 | func WaitToConnect(ctx context.Context, bindAddr string, ports []int, interval time.Duration) (err error) { |
no test coverage detected