diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 3fea4851c7..2cb9ab8996 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -155,7 +155,6 @@ func sessionHandler(session ssh.Session) { process.SetSysProcAttribute(cmd) wg := &sync.WaitGroup{} - wg.Add(2) if err = cmd.Start(); err != nil { log.Error("SSH: Start: %v", err) @@ -169,21 +168,19 @@ func sessionHandler(session ssh.Session) { } }() - go func() { - defer wg.Done() + wg.Go(func() { defer stdout.Close() if _, err := io.Copy(session, stdout); err != nil { log.Error("Failed to write stdout to session. %s", err) } - }() + }) - go func() { - defer wg.Done() + wg.Go(func() { defer stderr.Close() if _, err := io.Copy(session.Stderr(), stderr); err != nil { log.Error("Failed to write stderr to session. %s", err) } - }() + }) // Ensure all the output has been written before we wait on the command // to exit. diff --git a/modules/templates/scopedtmpl/scopedtmpl_test.go b/modules/templates/scopedtmpl/scopedtmpl_test.go index 774b8c7d42..dbf11e97c2 100644 --- a/modules/templates/scopedtmpl/scopedtmpl_test.go +++ b/modules/templates/scopedtmpl/scopedtmpl_test.go @@ -54,17 +54,14 @@ func TestScopedTemplateSetFuncMap(t *testing.T) { out1 := bytes.Buffer{} out2 := bytes.Buffer{} wg := sync.WaitGroup{} - wg.Add(2) - go func() { + wg.Go(func() { err := ts.newExecutor(funcMap1).Execute(&out1, nil) assert.NoError(t, err) - wg.Done() - }() - go func() { + }) + wg.Go(func() { err := ts.newExecutor(funcMap2).Execute(&out2, nil) assert.NoError(t, err) - wg.Done() - }() + }) wg.Wait() assert.Equal(t, "base1\ntest1\nbase1\ntest1", out1.String()) assert.Equal(t, "base2\ntest2\nbase2\ntest2", out2.String()) diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index f6a7a4f574..8f20814251 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -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() } diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go index 93dd100680..c327f76305 100644 --- a/tests/integration/api_packages_container_test.go +++ b/tests/integration/api_packages_container_test.go @@ -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() }) diff --git a/tests/integration/api_packages_maven_test.go b/tests/integration/api_packages_maven_test.go index 468b32f2b8..bad74dc597 100644 --- a/tests/integration/api_packages_maven_test.go +++ b/tests/integration/api_packages_maven_test.go @@ -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() }) diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go index c830086e3f..71e35cceab 100644 --- a/tests/integration/git_misc_test.go +++ b/tests/integration/git_misc_test.go @@ -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) diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index 3bcea83f43..dbaabc380b 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -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() }