diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-11-25 06:47:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 13:47:46 +0800 |
commit | a1ae83f36ece5e37c738bd796227cf5990ccc030 (patch) | |
tree | 9d885adb69db89450b845fd936d3eb5fb91420a1 /tests/integration/api_packages_container_test.go | |
parent | 9ce5e092f3f0e0048c49419c4ccd886e817a764f (diff) | |
download | gitea-a1ae83f36ece5e37c738bd796227cf5990ccc030.tar.gz gitea-a1ae83f36ece5e37c738bd796227cf5990ccc030.zip |
Workaround for container registry push/pull errors (#21862)
This PR addresses #19586
I added a mutex to the upload version creation which will prevent the
push errors when two requests try to create these database entries. I'm
not sure if this should be the final solution for this problem.
I added a workaround to allow a reupload of missing blobs. Normally a
reupload is skipped because the database knows the blob is already
present. The workaround checks if the blob exists on the file system.
This should not be needed anymore with the above fix so I marked this
code to be removed with Gitea v1.20.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'tests/integration/api_packages_container_test.go')
-rw-r--r-- | tests/integration/api_packages_container_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go index ba76ee4baa..60cbecd067 100644 --- a/tests/integration/api_packages_container_test.go +++ b/tests/integration/api_packages_container_test.go @@ -6,10 +6,12 @@ package integration import ( "bytes" + "crypto/sha256" "encoding/base64" "fmt" "net/http" "strings" + "sync" "testing" "code.gitea.io/gitea/models/db" @@ -594,6 +596,32 @@ func TestPackageContainer(t *testing.T) { }) } + // https://github.com/go-gitea/gitea/issues/19586 + t.Run("ParallelUpload", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + url := fmt.Sprintf("%sv2/%s/parallel", setting.AppURL, user.Name) + + var wg sync.WaitGroup + for i := 0; i < 10; i++ { + wg.Add(1) + + content := []byte{byte(i)} + digest := fmt.Sprintf("sha256:%x", sha256.Sum256(content)) + + go func() { + defer wg.Done() + + req := NewRequestWithBody(t, "POST", fmt.Sprintf("%s/blobs/uploads?digest=%s", url, digest), bytes.NewReader(content)) + addTokenAuthHeader(req, userToken) + resp := MakeRequest(t, req, http.StatusCreated) + + assert.Equal(t, digest, resp.Header().Get("Docker-Content-Digest")) + }() + } + wg.Wait() + }) + t.Run("OwnerNameChange", func(t *testing.T) { defer tests.PrintCurrentTest(t)() |