Add timeout while waiting for ready in tests
This commit is contained in:
@@ -51,23 +51,22 @@ func waitForWebReady(t *testing.T, cli *client.Client, ID string, tlsConfig *tls
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("https://localhost:%s/ibmmq/rest/v1/admin/installation", getPort(t, cli, ID, 9443))
|
url := fmt.Sprintf("https://localhost:%s/ibmmq/rest/v1/admin/installation", getPort(t, cli, ID, 9443))
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
select {
|
||||||
req.SetBasicAuth("admin", devAdminPassword)
|
case <-time.After(1 * time.Second):
|
||||||
resp, err := httpClient.Do(req)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err == nil && resp.StatusCode == http.StatusOK {
|
req.SetBasicAuth("admin", devAdminPassword)
|
||||||
t.Log("MQ web server is ready")
|
resp, err := httpClient.Do(req.WithContext(ctx))
|
||||||
return
|
if err == nil && resp.StatusCode == http.StatusOK {
|
||||||
|
t.Log("MQ web server is ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("Timed out waiting for web server to become ready")
|
||||||
}
|
}
|
||||||
// conn, err := tls.Dial("tcp", a, &config)
|
|
||||||
// if err == nil {
|
|
||||||
// conn.Close()
|
|
||||||
// // Extra sleep to allow web apps to start
|
|
||||||
// time.Sleep(5 * time.Second)
|
|
||||||
// t.Log("MQ web server is ready")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -387,11 +387,19 @@ rerun:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForReady(t *testing.T, cli *client.Client, ID string) {
|
func waitForReady(t *testing.T, cli *client.Client, ID string) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
rc, _ := execContainer(t, cli, ID, "mqm", []string{"chkmqready"})
|
select {
|
||||||
if rc == 0 {
|
case <-time.After(1 * time.Second):
|
||||||
t.Log("MQ is ready")
|
rc, _ := execContainer(t, cli, ID, "mqm", []string{"chkmqready"})
|
||||||
return
|
if rc == 0 {
|
||||||
|
t.Log("MQ is ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("Timed out waiting for container to become ready")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user