test: return immediately on connect

if the connection is successfull then return immediately instead of doing
all the iterations.  It also solves a problem where connections are
leaked since there are multiple Dial but only one Close.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2022-07-05 11:09:51 +02:00
parent a406b950e4
commit c02f793bab

View File

@ -1081,15 +1081,17 @@ func WaitForFile(path string) (err error) {
// WaitForService blocks, waiting for some service listening on given host:port // WaitForService blocks, waiting for some service listening on given host:port
func WaitForService(address url.URL) { func WaitForService(address url.URL) {
// Wait for podman to be ready // Wait for podman to be ready
var conn net.Conn
var err error var err error
for i := 1; i <= 5; i++ { for i := 1; i <= 5; i++ {
var conn net.Conn
conn, err = net.Dial("tcp", address.Host) conn, err = net.Dial("tcp", address.Host)
if err != nil { if err == nil {
conn.Close()
break
}
// Podman not available yet... // Podman not available yet...
time.Sleep(time.Duration(i) * time.Second) time.Sleep(time.Duration(i) * time.Second)
} }
}
Expect(err).ShouldNot(HaveOccurred()) Expect(err).ShouldNot(HaveOccurred())
conn.Close()
} }