From 2194379a0498c3b7df6959bfef40ad050e0f9852 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 13 Jan 2020 20:41:06 +0100 Subject: [PATCH] Fix pull on ContainerStart wrapper used in tests ContainerStart wrapper used in tests was not waiting for the pull to finish, causing flakiness, e.g. in the `TestDockerStart`. --- libbeat/tests/docker/docker.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libbeat/tests/docker/docker.go b/libbeat/tests/docker/docker.go index ce137da641cd..afa18317eb9d 100644 --- a/libbeat/tests/docker/docker.go +++ b/libbeat/tests/docker/docker.go @@ -20,6 +20,8 @@ package docker import ( "context" + "github.com/pkg/errors" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" @@ -41,9 +43,11 @@ func NewClient() (Client, error) { // ContainerStart pulls and starts the given container func (c Client) ContainerStart(image string, cmd []string, labels map[string]string) (string, error) { ctx := context.Background() - if _, err := c.cli.ImagePull(ctx, image, types.ImagePullOptions{}); err != nil { - return "", err + respBody, err := c.cli.ImagePull(ctx, image, types.ImagePullOptions{}) + if err != nil { + return "", errors.Wrapf(err, "pullling image %s", image) } + defer respBody.Close() resp, err := c.cli.ContainerCreate(ctx, &container.Config{ Image: image, @@ -51,11 +55,11 @@ func (c Client) ContainerStart(image string, cmd []string, labels map[string]str Labels: labels, }, nil, nil, "") if err != nil { - return "", err + return "", errors.Wrap(err, "creating container") } if err := c.cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { - return "", err + return "", errors.Wrap(err, "starting container") } return resp.ID, nil