Add timeout while waiting for ready in tests

This commit is contained in:
Arthur Barr
2018-06-13 16:42:00 +01:00
parent 2e3dee931c
commit 63ce0b3377
2 changed files with 26 additions and 19 deletions

View File

@@ -387,11 +387,19 @@ rerun:
}
func waitForReady(t *testing.T, cli *client.Client, ID string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
for {
rc, _ := execContainer(t, cli, ID, "mqm", []string{"chkmqready"})
if rc == 0 {
t.Log("MQ is ready")
return
select {
case <-time.After(1 * time.Second):
rc, _ := execContainer(t, cli, ID, "mqm", []string{"chkmqready"})
if rc == 0 {
t.Log("MQ is ready")
return
}
case <-ctx.Done():
t.Fatal("Timed out waiting for container to become ready")
}
}
}