From a1a1a0eef63bd09136ab76663bdbc3b0ab3a4931 Mon Sep 17 00:00:00 2001 From: Matthew McNew Date: Mon, 7 Jan 2019 11:18:51 -0600 Subject: [PATCH] Ensure container removed in test helpers * Fixes flaky clear cache tests Signed-off-by: Matthew McNew Signed-off-by: Emily Casey --- build_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build_test.go b/build_test.go index d170cf70d..4ea5af4bf 100644 --- a/build_test.go +++ b/build_test.go @@ -18,6 +18,7 @@ import ( "github.com/buildpack/lifecycle" dockertypes "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" dockercontainer "github.com/docker/docker/api/types/container" "github.com/golang/mock/gomock" "github.com/google/uuid" @@ -856,7 +857,7 @@ func runInImage(t *testing.T, dockerCli *docker.Client, volumes []string, repoNa Binds: volumes, }, nil, "") h.AssertNil(t, err) - defer dockerCli.ContainerRemove(ctx, ctr.ID, dockertypes.ContainerRemoveOptions{Force: true}) + okChan, errChan := dockerCli.ContainerWait(ctx, ctr.ID, container.WaitConditionRemoved) var buf bytes.Buffer err = dockerCli.RunContainer(ctx, ctr.ID, &buf, &buf) @@ -864,5 +865,10 @@ func runInImage(t *testing.T, dockerCli *docker.Client, volumes []string, repoNa t.Fatalf("Expected nil: %s", errors.Wrap(err, buf.String())) } + select { + case <-okChan: + case err = <-errChan: + h.AssertNil(t, err) + } return buf.String() }