diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index f90913753d..ddd72b385b 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -15,6 +15,7 @@ import ( "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/integration-cli/cli" "github.com/moby/moby/v2/integration-cli/cli/build" + "golang.org/x/sync/errgroup" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/icmd" @@ -134,41 +135,38 @@ func (s *DockerRegistrySuite) TestConcurrentPush(c *testing.T) { var repos []string for _, tag := range []string{"push1", "push2", "push3"} { repo := fmt.Sprintf("%v:%v", imgRepo, tag) - buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(` - FROM busybox - ENTRYPOINT ["/bin/echo"] - ENV FOO foo - ENV BAR bar - CMD echo %s -`, repo))) + buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf("FROM busybox\nCMD echo hello from %s\n", repo))) repos = append(repos, repo) } + cleanup := func() { + args := append([]string{"rmi", "--force"}, repos...) + cli.DockerCmd(c, args...) + } + defer cleanup() + // Push tags, in parallel - results := make(chan error, len(repos)) - + var eg errgroup.Group for _, repo := range repos { - go func(repo string) { + eg.Go(func() error { result := icmd.RunCommand(dockerBinary, "push", repo) - results <- result.Error - }(repo) - } - - for range repos { - err := <-results - assert.NilError(c, err, "concurrent push failed with error: %v", err) + // check the result, but don't fail immediately (result.Assert) + // to prevent the errgroup from not completing. + assert.Check(c, result.Equal(icmd.Success)) + return result.Error + }) } + assert.NilError(c, eg.Wait()) // Clear local images store. - args := append([]string{"rmi"}, repos...) - cli.DockerCmd(c, args...) + cleanup() // Re-pull and run individual tags, to make sure pushes succeeded for _, repo := range repos { cli.DockerCmd(c, "pull", repo) cli.DockerCmd(c, "inspect", repo) out := cli.DockerCmd(c, "run", "--rm", repo).Combined() - assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo) + assert.Equal(c, strings.TrimSpace(out), "hello from "+repo) } }