Browse code

fix flaky TestRunContainerWithRmFlag tests (take 2)

This is a new attempt on making these tests less flaky. The previous attempt in
commit 585c147b7a78c02f04773ab611bb41268ed1aa3b assumed that the test was failing
if the test-daemon still had unrelated containers present from other tests, but
it appears that the actual reason for the tests to be flaky may be that the `--rm`
option was moved to the daemon side and an asynchronous operation. As a result,
the container may not yet be removed once the `docker run` completes, which happens
frequently on Windows (likely be- cause removing containers is somewhat slower
on Windows).

This patch adds a retry-loop (using `poll.WaitOn()`) to wait for the container
to be removed.

make DOCKER_GRAPHDRIVER=vfs TEST_FILTER='TestRunContainerWithRmFlag' test-integration

INFO: Testing against a local daemon
=== RUN TestDockerSuite
=== RUN TestDockerSuite/TestRunContainerWithRmFlagCannotStartContainer
=== RUN TestDockerSuite/TestRunContainerWithRmFlagExitCodeNotEqualToZero
--- PASS: TestDockerSuite (1.00s)
--- PASS: TestDockerSuite/TestRunContainerWithRmFlagCannotStartContainer (0.50s)
--- PASS: TestDockerSuite/TestRunContainerWithRmFlagExitCodeNotEqualToZero (0.49s)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2022/06/21 23:21:37
Showing 1 changed files
... ...
@@ -34,6 +34,7 @@ import (
34 34
 	"github.com/moby/sys/mountinfo"
35 35
 	"gotest.tools/v3/assert"
36 36
 	"gotest.tools/v3/icmd"
37
+	"gotest.tools/v3/poll"
37 38
 	"gotest.tools/v3/skip"
38 39
 )
39 40
 
... ...
@@ -2750,11 +2751,7 @@ func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *testin
2750 2750
 		ExitCode: 1,
2751 2751
 	})
2752 2752
 
2753
-	cli.Docker(cli.Args("container", "inspect", name)).Assert(c, icmd.Expected{
2754
-		ExitCode: 1,
2755
-		Out:      "[]\n",
2756
-		Err:      "o such container", // (N|n)o such container
2757
-	})
2753
+	poll.WaitOn(c, containerRemoved(name))
2758 2754
 }
2759 2755
 
2760 2756
 func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *testing.T) {
... ...
@@ -2763,11 +2760,21 @@ func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *testing.
2763 2763
 		ExitCode: 127,
2764 2764
 	})
2765 2765
 
2766
-	cli.Docker(cli.Args("container", "inspect", name)).Assert(c, icmd.Expected{
2767
-		ExitCode: 1,
2768
-		Out:      "[]\n",
2769
-		Err:      "o such container", // (N|n)o such container
2770
-	})
2766
+	poll.WaitOn(c, containerRemoved(name))
2767
+}
2768
+
2769
+func containerRemoved(name string) poll.Check {
2770
+	return func(l poll.LogT) poll.Result {
2771
+		err := cli.Docker(cli.Args("container", "inspect", "--format='{{.ID}}'", name)).Compare(icmd.Expected{
2772
+			ExitCode: 1,
2773
+			Out:      "",
2774
+			Err:      "o such container", // (N|n)o such container
2775
+		})
2776
+		if err != nil {
2777
+			return poll.Continue("waiting for container '%s' to be removed", name)
2778
+		}
2779
+		return poll.Success()
2780
+	}
2771 2781
 }
2772 2782
 
2773 2783
 func (s *DockerSuite) TestRunPIDHostWithChildIsKillable(c *testing.T) {