فهرست منبع

Fix Flakiness in TestRmRestartingContainer

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Josh Hawn 8 سال پیش
والد
کامیت
e979cf7464
1فایلهای تغییر یافته به همراه13 افزوده شده و 0 حذف شده
  1. 13 0
      integration-cli/docker_cli_rm_test.go

+ 13 - 0
integration-cli/docker_cli_rm_test.go

@@ -3,6 +3,8 @@ package main
 import (
 import (
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
+	"strings"
+	"time"
 
 
 	"github.com/docker/docker/integration-cli/checker"
 	"github.com/docker/docker/integration-cli/checker"
 	"github.com/docker/docker/integration-cli/cli/build"
 	"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")
 	dockerCmd(c, "run", "--name", name, "--restart=always", "busybox", "date")
 
 
 	res, _, err := dockerCmdWithError("rm", name)
 	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(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, "cannot remove a restarting container")
 	c.Assert(res, checker.Contains, "Stop the container before attempting removal or force remove")
 	c.Assert(res, checker.Contains, "Stop the container before attempting removal or force remove")