From b240a84ce009a53fee3c941ca5f696344e4c5d83 Mon Sep 17 00:00:00 2001 From: Arthur Barr Date: Mon, 12 Mar 2018 16:28:40 +0000 Subject: [PATCH] Fix occasional timing error in tests --- test/docker/docker_api_test_util.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/docker/docker_api_test_util.go b/test/docker/docker_api_test_util.go index 7c54b3e..5409b45 100644 --- a/test/docker/docker_api_test_util.go +++ b/test/docker/docker_api_test_util.go @@ -309,13 +309,23 @@ func execContainerWithOutput(t *testing.T, cli *client.Client, ID string, user s if err != nil { t.Fatal(err) } - cli.ContainerExecStart(context.Background(), resp.ID, types.ExecStartCheck{ + err = cli.ContainerExecStart(context.Background(), resp.ID, types.ExecStartCheck{ Detach: false, Tty: false, }) if err != nil { t.Fatal(err) } + // Wait for the command to finish + for { + inspect, err := cli.ContainerExecInspect(context.Background(), resp.ID) + if err != nil { + t.Fatal(err) + } + if !inspect.Running { + break + } + } buf := new(bytes.Buffer) // Each output line has a header, which needs to be removed _, err = stdcopy.StdCopy(buf, buf, hijack.Reader)