diff options
author | Gusted <gusted@noreply.codeberg.org> | 2025-01-09 18:39:38 +0100 |
---|---|---|
committer | Gusted <gusted@noreply.codeberg.org> | 2025-01-09 18:39:38 +0100 |
commit | 46e15e57f782c968f533bd6a74b7da82c6ddcbaf (patch) | |
tree | 186130983490799b4098f4c8a26dc62180690e9d /tests | |
parent | i18n: update of translations from Codeberg Translate (#6451) (diff) | |
download | forgejo-46e15e57f782c968f533bd6a74b7da82c6ddcbaf.tar.xz forgejo-46e15e57f782c968f533bd6a74b7da82c6ddcbaf.zip |
port(gitea#31954): Add lock for parallel maven upload (#6513)
Backport #31851
Fix #30171
---
Fixes https://github.com/go-gitea/gitea/issues/30171, this is also a
issue in Forgejo. Backport the implementation that uses the existing
sync module which does not work for multiple instances which is
perfectly fine for Forgejo for now.
(cherry picked from commit 9c990ac043a0167dc59f1c822988ed2316f7c1df)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6513
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/api_packages_maven_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/integration/api_packages_maven_test.go b/tests/integration/api_packages_maven_test.go index 7ada3b28ac..b453f10b69 100644 --- a/tests/integration/api_packages_maven_test.go +++ b/tests/integration/api_packages_maven_test.go @@ -8,6 +8,7 @@ import ( "net/http" "strconv" "strings" + "sync" "testing" "code.gitea.io/gitea/models/db" @@ -254,3 +255,35 @@ func TestPackageMaven(t *testing.T) { assert.NotContains(t, resp.Body.String(), "Internal server error") }) } + +func TestPackageMavenConcurrent(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + groupID := "com.gitea" + artifactID := "test-project" + packageVersion := "1.0.1" + + root := fmt.Sprintf("/api/packages/%s/maven/%s/%s", user.Name, strings.ReplaceAll(groupID, ".", "/"), artifactID) + + putFile := func(t *testing.T, path, content string, expectedStatus int) { + req := NewRequestWithBody(t, "PUT", root+path, strings.NewReader(content)). + AddBasicAuth(user.Name) + MakeRequest(t, req, expectedStatus) + } + + t.Run("Concurrent Upload", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + var wg sync.WaitGroup + for i := 0; i < 10; i++ { + wg.Add(1) + go func(i int) { + putFile(t, fmt.Sprintf("/%s/%s.jar", packageVersion, strconv.Itoa(i)), "test", http.StatusCreated) + wg.Done() + }(i) + } + wg.Wait() + }) +} |