Browse code

Another attempt to deflake TestPullFromCentralRegistryImplicitRefParts

Retries after v1 fallbacks were added in #20411. The test still appears
to be flaky. There are two potential problems. The initial pull was not
protected against pulling from v1, so it could be giving us a different
hello-world image to compare against. Also, after experiencing a v1
fallback, we need to restore the original image before doing the next
pull, because otherwise the "Image is up to date for hello-world:latest"
message will not show up as expected.

See #17214.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2016/03/02 10:02:06
Showing 1 changed files
... ...
@@ -74,18 +74,10 @@ func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) {
74 74
 // multiple images.
75 75
 func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *check.C) {
76 76
 	testRequires(c, DaemonIsLinux)
77
-	s.Cmd(c, "pull", "hello-world")
78
-	defer deleteImages("hello-world")
79 77
 
80
-	for _, i := range []string{
81
-		"hello-world",
82
-		"hello-world:latest",
83
-		"library/hello-world",
84
-		"library/hello-world:latest",
85
-		"docker.io/library/hello-world",
86
-		"index.docker.io/library/hello-world",
87
-	} {
88
-		out := s.Cmd(c, "pull", i)
78
+	// Pull hello-world from v2
79
+	pullFromV2 := func(ref string) (int, string) {
80
+		out := s.Cmd(c, "pull", "hello-world")
89 81
 		v1Retries := 0
90 82
 		for strings.Contains(out, "this image was pulled from a legacy registry") {
91 83
 			// Some network errors may cause fallbacks to the v1
... ...
@@ -95,17 +87,51 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *chec
95 95
 			// few retries if we end up with a v1 pull.
96 96
 
97 97
 			if v1Retries > 2 {
98
-				c.Fatalf("too many v1 fallback incidents when pulling %s", i)
98
+				c.Fatalf("too many v1 fallback incidents when pulling %s", ref)
99 99
 			}
100 100
 
101
-			s.Cmd(c, "rmi", i)
102
-			out = s.Cmd(c, "pull", i)
101
+			s.Cmd(c, "rmi", ref)
102
+			out = s.Cmd(c, "pull", ref)
103 103
 
104 104
 			v1Retries++
105 105
 		}
106
+
107
+		return v1Retries, out
108
+	}
109
+
110
+	pullFromV2("hello-world")
111
+	defer deleteImages("hello-world")
112
+
113
+	s.Cmd(c, "tag", "hello-world", "hello-world-backup")
114
+
115
+	for _, ref := range []string{
116
+		"hello-world",
117
+		"hello-world:latest",
118
+		"library/hello-world",
119
+		"library/hello-world:latest",
120
+		"docker.io/library/hello-world",
121
+		"index.docker.io/library/hello-world",
122
+	} {
123
+		var out string
124
+		for {
125
+			var v1Retries int
126
+			v1Retries, out = pullFromV2(ref)
127
+
128
+			// Keep repeating the test case until we don't hit a v1
129
+			// fallback case. We won't get the right "Image is up
130
+			// to date" message if the local image was replaced
131
+			// with one pulled from v1.
132
+			if v1Retries == 0 {
133
+				break
134
+			}
135
+			s.Cmd(c, "rmi", ref)
136
+			s.Cmd(c, "tag", "hello-world-backup", "hello-world")
137
+		}
106 138
 		c.Assert(out, checker.Contains, "Image is up to date for hello-world:latest")
107 139
 	}
108 140
 
141
+	s.Cmd(c, "rmi", "hello-world-backup")
142
+
109 143
 	// We should have a single entry in images.
110 144
 	img := strings.TrimSpace(s.Cmd(c, "images"))
111 145
 	splitImg := strings.Split(img, "\n")