Skip to content

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
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