Skip to content

Conversation

@ferhatelmas
Copy link
Contributor

Related to #1753

Copilot AI review requested due to automatic review settings December 11, 2025 23:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the paralleltest linter in the golangci configuration and adds t.Parallel() calls to test functions throughout the codebase to allow tests to run concurrently, improving test execution time.

Key changes:

  • Added paralleltest to the enabled linters list in .golangci.yaml
  • Added t.Parallel() calls to top-level test functions and subtests across the entire codebase
  • Applied parallelization to both standalone test functions and testify/suite-based tests

Reviewed changes

Copilot reviewed 165 out of 165 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.golangci.yaml Enabled the paralleltest linter
worktree_test.go Added t.Parallel() to 7 test functions including suite runner and standalone tests
worktree_status_test.go Added t.Parallel() to 1 test function
worktree_commit_test.go Added t.Parallel() to 2 test functions
utils/trace/trace_test.go Added t.Parallel() to 5 test functions that modify global state
utils/sync/bytes_test.go Added t.Parallel() to 1 test function
utils/merkletrie/* Added t.Parallel() to 7 test suite runners
utils/ioutil/context_test.go Added t.Parallel() to 6 test functions
utils/ioutil/common_test.go Added t.Parallel() to 1 test suite runner
utils/diff/diff_ext_test.go Added t.Parallel() to 1 test suite runner
utils/convert/*.go Added t.Parallel() to 4 test functions and their subtests
utils/binary/read_test.go Added t.Parallel() to 1 test suite runner
tests/pack/*.go Added t.Parallel() to 4 test functions
submodule_test.go Added t.Parallel() to 1 test suite runner
storage/transactional/*.go Added t.Parallel() to 7 test suite runners
storage/filesystem/*.go Added t.Parallel() to 5 test suite runners and standalone tests
status_test.go Added t.Parallel() to 1 test function and its subtests
repository*.go Added t.Parallel() to 2 test suite runners and 1 standalone test
remote_test.go Added t.Parallel() to 2 test functions
prune_test.go Added t.Parallel() to 1 test suite runner
plumbing/transport/*.go Added t.Parallel() to 15 test suite runners and standalone tests
plumbing/transport/ssh/*.go Added t.Parallel() to 9 test functions including one that modifies global state
plumbing/transport/http/*.go Added t.Parallel() to 7 test suite runners and standalone tests
plumbing/transport/git/*.go Added t.Parallel() to 2 test suite runners
plumbing/transport/file/*.go Added t.Parallel() to 3 test suite runners
plumbing/storer/*.go Added t.Parallel() to 2 test suite runners
plumbing/revlist/*.go Added t.Parallel() to 1 test suite runner
plumbing/reference_test.go Added t.Parallel() to 1 test suite runner
plumbing/protocol/packp/*.go Added t.Parallel() to 17 test suite runners and standalone tests
plumbing/objectid_test.go Added t.Parallel() to 3 test functions and their subtests
plumbing/object_test.go Added t.Parallel() to 1 test suite runner
plumbing/object/*.go Added t.Parallel() to 15 test suite runners
plumbing/memory_test.go Added t.Parallel() to 1 test suite runner
plumbing/hasher_test.go Added t.Parallel() to 3 test functions and their subtests
plumbing/hash_test.go Added t.Parallel() to 1 test suite runner
plumbing/hash/hash_test.go Added t.Parallel() to 2 test functions and their subtests that modify global state
plumbing/format/revfile/*.go Added t.Parallel() to 2 test functions and their subtests
plumbing/format/pktline/*.go Added t.Parallel() to 7 test suite runners and standalone tests
plumbing/format/packfile/*.go Added t.Parallel() to 10 test suite runners and standalone tests with subtests
plumbing/format/objfile/*.go Added t.Parallel() to 2 test suite runners
plumbing/format/index/*.go Added t.Parallel() to 7 test functions
plumbing/format/idxfile/*.go Added t.Parallel() to 4 test suite runners and standalone tests
plumbing/format/gitignore/*.go Added t.Parallel() to 2 test suite runners
plumbing/format/gitattributes/*.go Added t.Parallel() to 3 test suite runners
plumbing/format/diff/*.go Added t.Parallel() to 1 test suite runner
plumbing/format/config/*.go Added t.Parallel() to 6 test suite runners
plumbing/format/commitgraph/*.go Added t.Parallel() to 2 test suite runners and standalone tests
plumbing/filemode/*.go Added t.Parallel() to 1 test suite runner
plumbing/cache/*.go Added t.Parallel() to 2 test suite runners
options_test.go Added t.Parallel() to 1 test suite runner
internal/url/*.go Added t.Parallel() to 1 test suite runner
internal/revision/*.go Added t.Parallel() to 2 test suite runners
config/*.go Added t.Parallel() to 6 test suite runners and standalone tests
common_test.go Added t.Parallel() to 1 test suite runner
blame_test.go Added t.Parallel() to 1 test suite runner
backend/http/http_test.go Added t.Parallel() to 3 test functions
Comments suppressed due to low confidence (4)

plumbing/transport/ssh/common_test.go:178

  • The TestIssue70Suite test modifies the global DefaultAuthBuilder variable (lines 159-161) and then relies on a defer to restore it. However, since the test is marked to run in parallel (line 158), other tests could be accessing DefaultAuthBuilder concurrently, leading to data races or unexpected behavior. Tests that modify global state should not run in parallel with other tests that might use that same global state.
    utils/trace/trace_test.go:85
  • The trace tests modify global state through SetLogger and SetTarget functions, but SetLogger (line 50-52 of trace.go) directly assigns to the global logger variable without synchronization, while SetTarget uses atomic operations. When tests run in parallel, concurrent calls to SetLogger could cause data races. The tests should either not run in parallel, or the trace package needs to be refactored to be thread-safe for logger changes.
    plumbing/hash/hash_test.go:55
  • The TestRegisterHash test and its subtests modify the global algos map through RegisterHash calls. Even though there's a defer reset() at the parent test level, the subtests run in parallel (line 44) and can interfere with each other by registering different hash implementations concurrently. The global map is not protected by any synchronization mechanism, which could lead to data races when tests run in parallel.
    plumbing/hash/hash_test.go:107
  • The TestSha1Collision test and its subtests also modify the global algos map through RegisterHash calls (line 80). With subtests running in parallel (line 87), concurrent modifications to the global map can cause data races. The defer reset() only protects against interference with other top-level tests, not between parallel subtests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas
Copy link
Contributor Author

Seems like 25% speedup

image image

@onee-only
Copy link
Contributor

I'm surprised that the test workflow didn't result in data race as described in #1766. In my local test, a lot of tests failed due to the race. Is this only happening in my machine?

@pjbgf
Copy link
Member

pjbgf commented Dec 12, 2025

@ferhatelmas looking across a range of successful executions, it feels like the overall execution time hasn't changed much:
image

The same seems to be the case when looking solely at the time taken for the Test to run:
image

I'm not sure this is because GOMAXPROCS is not set properly within the GH runner, or for other reason. But given that the focus of this PR is to enable the linter and ensure the code complies, I'm happy to merge as-is and any additional improvement on test execution time can be done on a follow-up PR.

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ferhatelmas thanks for working on this. 🙇

@pjbgf pjbgf merged commit e83cbb9 into go-git:main Dec 12, 2025
16 checks passed
@ferhatelmas ferhatelmas deleted the paralleltest branch December 12, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants