mirror of
https://github.com/containers/podman.git
synced 2025-06-27 05:26:50 +08:00
test: reduce sleep interval
there is no need to use such long sleep intervals for such cheap operations like opening a connection or stat'ing a file. Also make WaitForService() honor defaultWaitTimeout. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -1064,13 +1064,13 @@ func digShort(container, lookupName string, matchNames []string, p *PodmanTestIn
|
|||||||
// WaitForFile to be created in defaultWaitTimeout seconds, returns false if file not created
|
// WaitForFile to be created in defaultWaitTimeout seconds, returns false if file not created
|
||||||
func WaitForFile(path string) (err error) {
|
func WaitForFile(path string) (err error) {
|
||||||
until := time.Now().Add(time.Duration(defaultWaitTimeout) * time.Second)
|
until := time.Now().Add(time.Duration(defaultWaitTimeout) * time.Second)
|
||||||
for i := 1; time.Now().Before(until); i++ {
|
for time.Now().Before(until) {
|
||||||
_, err = os.Stat(path)
|
_, err = os.Stat(path)
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return nil
|
return nil
|
||||||
case errors.Is(err, os.ErrNotExist):
|
case errors.Is(err, os.ErrNotExist):
|
||||||
time.Sleep(time.Duration(i) * time.Second)
|
time.Sleep(10 * time.Millisecond)
|
||||||
default:
|
default:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1078,11 +1078,12 @@ func WaitForFile(path string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForService blocks, waiting for some service listening on given host:port
|
// WaitForService blocks for defaultWaitTimeout seconds, 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 err error
|
var err error
|
||||||
for i := 1; i <= 5; i++ {
|
until := time.Now().Add(time.Duration(defaultWaitTimeout) * time.Second)
|
||||||
|
for time.Now().Before(until) {
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
conn, err = net.Dial("tcp", address.Host)
|
conn, err = net.Dial("tcp", address.Host)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -1091,7 +1092,7 @@ func WaitForService(address url.URL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Podman not available yet...
|
// Podman not available yet...
|
||||||
time.Sleep(time.Duration(i) * time.Second)
|
time.Sleep(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user