refactor(waitgroup): replace Add/Done goroutines with WaitGroup.Go (#37764)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
This commit is contained in:
Copilot
2026-05-18 23:22:32 +08:00
committed by GitHub
parent e60ca35d52
commit 912afcaa51
7 changed files with 22 additions and 42 deletions
+3 -6
View File
@@ -171,9 +171,8 @@ func testAPICreateIssueParallel(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
wg.Add(1)
go func(parentT *testing.T, i int) {
parentT.Run(fmt.Sprintf("ParallelCreateIssue_%d", i), func(t *testing.T) {
wg.Go(func() {
t.Run(fmt.Sprintf("ParallelCreateIssue_%d", i), func(t *testing.T) {
newTitle := title + strconv.Itoa(i)
newBody := body + strconv.Itoa(i)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
@@ -192,10 +191,8 @@ func testAPICreateIssueParallel(t *testing.T) {
Content: newBody,
Title: newTitle,
})
wg.Done()
})
}(t, i)
})
}
wg.Wait()
}
@@ -766,20 +766,16 @@ func TestPackageContainer(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
wg.Add(1)
content := []byte{byte(i)}
digest := fmt.Sprintf("sha256:%x", sha256.Sum256(content))
go func() {
defer wg.Done()
wg.Go(func() {
req := NewRequestWithBody(t, "POST", fmt.Sprintf("%s/blobs/uploads?digest=%s", url, digest), bytes.NewReader(content)).
AddTokenAuth(userToken)
resp := MakeRequest(t, req, http.StatusCreated)
assert.Equal(t, digest, resp.Header().Get("Docker-Content-Digest"))
}()
})
}
wg.Wait()
})
+2 -4
View File
@@ -321,11 +321,9 @@ func TestPackageMavenConcurrent(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
wg.Add(1)
go func(i int) {
wg.Go(func() {
putFile(t, fmt.Sprintf("/%s/%s.jar", packageVersion, strconv.Itoa(i)), "test", http.StatusCreated)
wg.Done()
}(i)
})
}
wg.Wait()
})
+4 -7
View File
@@ -63,17 +63,14 @@ func TestDataAsyncDoubleRead_Issue29101(t *testing.T) {
var data1, data2 []byte
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
wg.Go(func() {
data1, _ = io.ReadAll(r1)
assert.NoError(t, err)
wg.Done()
}()
go func() {
})
wg.Go(func() {
data2, _ = io.ReadAll(r2)
assert.NoError(t, err)
wg.Done()
}()
})
wg.Wait()
assert.Equal(t, testContent, data1)
assert.Equal(t, testContent, data2)
+3 -5
View File
@@ -180,14 +180,12 @@ func TestRepoCommitsStatusParallel(t *testing.T) {
var wg sync.WaitGroup
for i := range 10 {
wg.Add(1)
go func(parentT *testing.T, i int) {
parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
wg.Go(func() {
t.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
doAPICreateCommitStatusTest(ctx, path.Base(commitURL), commitstatus.CommitStatusPending, "testci")(t)
wg.Done()
})
}(t, i)
})
}
wg.Wait()
}