Improve performance when running a large number of JUnit tests
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- java
- Domain
- build-system, performance, testing-qa
Research direction
Start by tracing the java_test entry point and the Bazel test runner behavior described in the issue, especially how macro-generated targets, @Suite aggregation, sharding, and --flaky_test_attempts interact. Compare both reported test runs and the linked proof of concept; done should address large test collections without the reported performance increase or rerunning every test after a failure.
Written by the indexing model from the issue text.
Description
Title is a bit vague here, apologies for that.
Out-of-the-box, it is only possible to provide a single entry point to java_test, e.g.
java_test(
name = "com.example.MyLovelyUnitTest",
test_class = "com.example.MyLovelyUnitTest",
srcs = [ ... ],
# etc etc
)
If one wishes to make a target from multiple classes, there are currently two well publicised workarounds:
- Use a macro wrapper;
- Use a
@Suiteor similar.
Unfortunately, each of these comes with a negative side effect wrt. performance:
- Using a macro wrapper to turn the glob of source files into distinct
java_testtargets is documented to have a significant performance impact due to having to create and tear-down workers. To give a rough idea of the impact of this, here are some numbers taken from a Bazel project with ~5000 unit tests using a@Suite:
$ bazel clean
$ time bazel test //... --build_tests_only --test_lang_filters=java --test_size_filters=small
...
Executed 498 out of 498 tests: 498 tests pass.
...
bazel test //... --build_tests_only --test_lang_filters=java 2.58s user 1.55s system 0% cpu 16:41.63 total
... vs using a macro wrapper + aggregate test_suite:
$ bazel clean
$ time bazel test //... --build_tests_only --test_lang_filters=java --test_size_filters=small
...
Executed 4691 out of 4691 tests: 4691 tests pass.
...
./bb bazel bz test //... --build_tests_only --test_lang_filters=java 2.72s user 1.69s system 0% cpu 26:47.95 total
Both of these runs were operating over the same set of tests, but using a separate java_test for each individual class causes the build time to increase by ~60%.
- Generating a
@Suite(either at compile time or dynamically via something likeAllTests) clashes with--flaky_test_attemptsas, if any test case fails, the entire suite is detected as having failed and so all tests are run again. This can be somewhat mitigated by sharding but there's a cap of 50 on the number of shards.
Option 1 is "okay" in cases where there are few, long-running tests; option 2 is "okay" for a lot of fast running tests. It would be nice to have a "one-size-fits-all" solution.
There has been an open issue in the main Bazel repository for a few years now that has a bit of overlap, but that one seems a bit more focused around convenience rather than performance. As the Java rules are being broken out, I thought it might make sense to move it over here for an updated discussion.
When I came across the original issue, I did a very quick-and-hacky PoC of how the built-in Bazel test runner could be updated to support multiple classes; however, on revisiting this I'm not sure if that would actually solve the performance problem on its own, as it looks as though the flaky test attempts is handled outside the test runner process, and so I'm guessing this solution would end up just working in the same way as a @Suite.
- Dominant language
- Starlark
- Stars
- 103
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_java
-
P4
Difficulty 4/5 3-5 days Newbie friendliness 55/100
bazelbuild/rules_java#360 · 4 comments · 2 reactions ·
-
P4
Difficulty 5/5 Over a week Newbie friendliness 35/100
bazelbuild/rules_java#354 · 8 comments ·
-
P3 question
Difficulty 3/5 1-2 days Newbie friendliness 45/100
bazelbuild/rules_java#339 · 1 comment ·
-
P3
Difficulty 4/5 3-5 days Newbie friendliness 35/100
bazelbuild/rules_java#325 · 8 comments ·
-
P4
Difficulty 4/5 3-5 days Newbie friendliness 35/100
bazelbuild/rules_java#316 · 2 reactions ·
All issues in bazelbuild/rules_java
Similar issues
-
Update to NCCL 2.32 Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
conda-forge/nccl-feedstock#166 ·
-
next-devel: s390x build fails — chccwdev/vmur/zkey missing from initramfs after s390utils 2.44 split Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
coreos/fedora-coreos-tracker#2228 ·
-
Python versions Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MunchLab/ceREEBerus#121 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
integration-meraki type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nautobot/nautobot-app-chatops#463 ·