Merge pull request #20841 from aaronlehmann/strengthen-TestPullFromCentralRegistryImplicitRefParts-2

Another attempt to deflake TestPullFromCentralRegistryImplicitRefParts
This commit is contained in:
Vincent Demeester 2016-03-02 10:43:27 +01:00
commit 4eb7a4916f

View file

@ -74,18 +74,10 @@ func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) {
// multiple images.
func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *check.C) {
testRequires(c, DaemonIsLinux)
s.Cmd(c, "pull", "hello-world")
defer deleteImages("hello-world")
for _, i := range []string{
"hello-world",
"hello-world:latest",
"library/hello-world",
"library/hello-world:latest",
"docker.io/library/hello-world",
"index.docker.io/library/hello-world",
} {
out := s.Cmd(c, "pull", i)
// Pull hello-world from v2
pullFromV2 := func(ref string) (int, string) {
out := s.Cmd(c, "pull", "hello-world")
v1Retries := 0
for strings.Contains(out, "this image was pulled from a legacy registry") {
// Some network errors may cause fallbacks to the v1
@ -95,17 +87,51 @@ func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *chec
// few retries if we end up with a v1 pull.
if v1Retries > 2 {
c.Fatalf("too many v1 fallback incidents when pulling %s", i)
c.Fatalf("too many v1 fallback incidents when pulling %s", ref)
}
s.Cmd(c, "rmi", i)
out = s.Cmd(c, "pull", i)
s.Cmd(c, "rmi", ref)
out = s.Cmd(c, "pull", ref)
v1Retries++
}
return v1Retries, out
}
pullFromV2("hello-world")
defer deleteImages("hello-world")
s.Cmd(c, "tag", "hello-world", "hello-world-backup")
for _, ref := range []string{
"hello-world",
"hello-world:latest",
"library/hello-world",
"library/hello-world:latest",
"docker.io/library/hello-world",
"index.docker.io/library/hello-world",
} {
var out string
for {
var v1Retries int
v1Retries, out = pullFromV2(ref)
// Keep repeating the test case until we don't hit a v1
// fallback case. We won't get the right "Image is up
// to date" message if the local image was replaced
// with one pulled from v1.
if v1Retries == 0 {
break
}
s.Cmd(c, "rmi", ref)
s.Cmd(c, "tag", "hello-world-backup", "hello-world")
}
c.Assert(out, checker.Contains, "Image is up to date for hello-world:latest")
}
s.Cmd(c, "rmi", "hello-world-backup")
// We should have a single entry in images.
img := strings.TrimSpace(s.Cmd(c, "images"))
splitImg := strings.Split(img, "\n")