mirror of
https://github.com/containers/podman.git
synced 2025-06-26 04:46:57 +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
|
||||
func WaitForFile(path string) (err error) {
|
||||
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)
|
||||
switch {
|
||||
case err == nil:
|
||||
return nil
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
time.Sleep(time.Duration(i) * time.Second)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
@ -1078,11 +1078,12 @@ func WaitForFile(path string) (err error) {
|
||||
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) {
|
||||
// Wait for podman to be ready
|
||||
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
|
||||
conn, err = net.Dial("tcp", address.Host)
|
||||
if err == nil {
|
||||
@ -1091,7 +1092,7 @@ func WaitForService(address url.URL) {
|
||||
}
|
||||
|
||||
// Podman not available yet...
|
||||
time.Sleep(time.Duration(i) * time.Second)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
}
|
||||
|
Reference in New Issue
Block a user