Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically setting shard_count on go_test based on t.Parallel() calls #1996

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

yushan26
Copy link

@yushan26 yushan26 commented Dec 17, 2024

What type of PR is this?

Uncomment one line below and remove others.

Bug fix
Feature
Documentation
Other

What package or component does this PR mostly affect?

For example:

language/go

cmd/gazelle
go_repository
all

What does this PR do? Why is it needed?
Bazel may not necessarily schedule tests cases under target in parallel and may assign one core to a target. This means that tests running in t.Parallel may run sequentially. To make sure that the test cases are truly parallelized on heavily loaded machines, you should instead set shard_count on the go_test target. We can automatically setting shard_count on go_test based on the number of t.Parallel() calls at the top level function. This matches what people expects under go test.
This PR counts the number of t.Parallel calls in each target of the top level function and set the shard_count to the number of calls to ensure the test target is truly parallelized

Which issues(s) does this PR fix?

Fixes #1997

Other notes for review

@yushan26 yushan26 force-pushed the divid-gazelle-shards branch from 76db7bb to 1f45778 Compare December 17, 2024 23:57
@@ -307,6 +310,9 @@ func goFileInfo(path, srcdir string) fileInfo {
info.hasMainFunction = true
break
}
if info.isTest {
info.numParallel += countParallel(fdecl)
Copy link
Member

Choose a reason for hiding this comment

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

Should we really be summing these up? My understanding has been that individual test functions in a file are not run in parallel, only the t.Parallel funcs in them. In that case taking the maximum would be more appropriate.

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.

Automatically setting shard_count on go_test based on t.Parallel() calls
3 participants