Skip to content

Commit

Permalink
Merge pull request #265 from concourse/fix-concurrent-push-race
Browse files Browse the repository at this point in the history
structure: fix flaky test due to concurrent push
  • Loading branch information
vito authored Feb 11, 2021
2 parents d47ad1f + 0643aac commit 3efedbd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"sync"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -665,15 +666,15 @@ func (example SemverTagPushExample) Run() {
ghttp.RespondWith(http.StatusCreated, "upload complete")(w, r)
})

actualTags := []string{}
pushedTags := new(sync.Map)
registry.RouteToHandler("PUT", regexp.MustCompile("/v2/test-image/manifests/.*"), func(w http.ResponseWriter, r *http.Request) {
tag := filepath.Base(r.URL.Path)

actualDigest, _, err := v1.SHA256(r.Body)
Expect(err).ToNot(HaveOccurred())
Expect(actualDigest.String()).To(Equal(digest.String()))

actualTags = append(actualTags, tag)
pushedTags.Store(tag, struct{}{})

ghttp.RespondWith(http.StatusOK, "manifest updated")(w, r)
})
Expand All @@ -697,6 +698,12 @@ func (example SemverTagPushExample) Run() {
} else {
Expect(err).ToNot(HaveOccurred())

actualTags := []string{}
pushedTags.Range(func(key, val interface{}) bool {
actualTags = append(actualTags, key.(string))
return true
})

Expect(actualTags).To(ConsistOf(example.PushedTags))

Expect(res.Version.Tag).To(BeElementOf(actualTags))
Expand Down

0 comments on commit 3efedbd

Please sign in to comment.