From e979cf74640213ffe4d883cb00adecb957056e9a Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Sun, 2 Apr 2017 17:45:30 -0700 Subject: [PATCH] Fix Flakiness in TestRmRestartingContainer Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) --- integration-cli/docker_cli_rm_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/integration-cli/docker_cli_rm_test.go b/integration-cli/docker_cli_rm_test.go index 6219932f2f..6ade39bd84 100644 --- a/integration-cli/docker_cli_rm_test.go +++ b/integration-cli/docker_cli_rm_test.go @@ -3,6 +3,8 @@ package main import ( "io/ioutil" "os" + "strings" + "time" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli/build" @@ -93,6 +95,17 @@ func (s *DockerSuite) TestRmRestartingContainer(c *check.C) { dockerCmd(c, "run", "--name", name, "--restart=always", "busybox", "date") res, _, err := dockerCmdWithError("rm", name) + + for strings.Contains(res, "cannot remove a running container") { + // The `date` command hasn't exited yet. It should end + // up in a "restarting" state if we wait a bit, though + // it is possible that it might be running again by + // that time. The wait period between each restart + // increases though so we just loop in this condition. + time.Sleep(100 * time.Millisecond) + res, _, err = dockerCmdWithError("rm", name) + } + c.Assert(err, checker.NotNil, check.Commentf("Expected error on rm a restarting container, got none")) c.Assert(res, checker.Contains, "cannot remove a restarting container") c.Assert(res, checker.Contains, "Stop the container before attempting removal or force remove")