Repository navigation
test: Add t.Parallel() to util/app tests - #28177
Conversation
β Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
Bundle ReportBundle size has no change β |
|
@lohitkolluri can you look into the test failures? |
0ade68c to
105fe2a
Compare
|
Hey Michael, I looked into the failures. The good news is they weren't caused by the t.Parallel() changes. The three failures were all CI infrastructure issues coming from the branch being behind upstream:
The root cause was that the branch was based on an older upstream commit using Ubuntu 25.10, which had stale download URLs and missing recent CI fixes. Upstream has since bumped the base image to 26.04 and fixed some E2E CRD cleanup issues. I rebased the branch on the latest upstream master and force-pushed. The local tests still pass cleanly. New CI is running now β hopefully it goes green. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #28177 +/- ##
==========================================
+ Coverage 64.67% 64.71% +0.03%
==========================================
Files 423 424 +1
Lines 58428 58667 +239
==========================================
+ Hits 37790 37965 +175
- Misses 17116 17166 +50
- Partials 3522 3536 +14 β View full report in Codecov by Harness. |
|
@crenshaw-dev All the tests are passing now updating the branch to latest did the job. |
blakepettersson
left a comment
There was a problem hiding this comment.
As I was mentioning in #27771 (review), it'd be nice if we could do some more substantial changes, so we can actually see if this will improve the runtime
a1d414c to
1b22dca
Compare
|
Expanded the PR significantly. Here is what changed:
The ~200 files were selected by scanning for blocker patterns (t.Setenv, t.Chdir, TestMain, os.Setenv, prometheus registry mutations, global log hooks, shared caches) and only adding t.Parallel() to files with none of these patterns. Branch is rebased on latest upstream/master, squashed to one commit. |
1c9469d to
4f6bdb3
Compare
|
Rebased on latest upstream/master. Performance comparison on a representative set of 25 modified packages (excluding git/GPG-dependent tests that have pre-existing infrastructure issues):
Per-package improvements in packages with multiple parallel-safe tests:
The overall improvement is moderate because package-level parallelism via In CI (GitHub Actions), the improvement will be more pronounced since CI runners typically have fewer cores, making the sequential vs parallel gap wider. Tests using any form of global state were intentionally left sequential: t.Setenv (35 files), shared caches, global log hooks, prometheus registries, and os.Stdout capture. |
4f6bdb3 to
310449c
Compare
|
@lohitkolluri looks like tests and linting broke. |
5fc0b7a to
5aac701
Compare
|
@lohitkolluri if you find some subset of tests unreasonably difficult to fix, it's okay to leave some out of the refactor. We want enough changes so that we can see some meaningful performance improvement, but not so many that you're bogged down in inherently-difficult tests for a long time. :-) |
|
Makes sense, thanks. I'll prioritize the tests that are clearly safe to parallelize and avoid spending too much time on the more complex cases. I will try to get a meaningful performance improvement without introducing unnecessary risk. |
2e619b3 to
b3f1bdf
Compare
Adds t.Parallel() to ~200 test files with local-only state. Removed from tests with shared state, stdout/stdin capture, or pre-existing data races exposed by concurrent execution. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
b3f1bdf to
9fea1d1
Compare
blakepettersson
left a comment
There was a problem hiding this comment.
@lohitkolluri if it's the case that util/lua is slower with these changes then IMO it makes sense to revert those changes. Otherwise LGTM
Collect testdata in a sequential phase before running parallel subtests so filesystem reads are not contended. Keeps t.Parallel() for CPU-bound Lua execution without regressing I/O-bound walks. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
|
Re-ran benchmarks on util/lua. The slowdown was from parallelizing I/O-bound walk tests. Refactored to collect testdata sequentially, then run Lua execution in parallel. Walk tests are now at parity with master (~15s vs ~21s), and the full package is ~55% faster than master (12.4s vs 27.3s median). -race passes. |
|
Updated performance numbers after the What changed: Walk-based tests in 25 modified packages (excl. git/GPG tests)
Top per-package speedups (
|
| Package | Sequential | Parallel | Speedup |
|---|---|---|---|
| util/cli | 9.14s | 2.36s | 74% |
| util/versions | 6.90s | 2.84s | 59% |
| server/events | 13.29s | 6.52s | 51% |
| server/cache | 15.04s | 7.82s | 48% |
util/lua (was slower, now fixed)
| Before fix | After fix | master | |
|---|---|---|---|
| Full package | 12.30s | 12.42s | 27.31s |
Walk tests (-parallel=8) |
15.92s | 15.07s | 21.49s |
No regression vs master. Full package ~55% faster at default settings.
Overall gains are moderate because go test -p already parallelizes across packages. t.Parallel() helps most in CPU-bound packages with many in-package tests.
Left sequential: t.Setenv (35 files), shared caches, log hooks, prometheus registries, stdout capture.
Add top-level t.Parallel() for paralleltest linter and remove unused getObj and getExpectedObjectList helpers. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
crenshaw-dev
left a comment
There was a problem hiding this comment.
Very nice work! Just a few more requests:
- Is the hack test script change necessary? If so, why?
- Why are tests being unmarked parallel in types_test.go?
- Can the health and customizations test changes be moved into a separate PR? They're significant enough to justify a separate review?
- Can new changes be pushed on top of the existing branch history instead of force-pushed? Previous force-pushes were fine, but now that I've done a baseline review, it'll be easier to review new individual commits.
Thanks so much!
|
Thanks for the detailed review!
Yes. It's needed so CI can actually take advantage of the
Those four tests already had
Makes sense. If you'd prefer, I can split the changes in
Absolutely. That makes sense now that you've completed a baseline review. I'll push any follow-up changes as incremental commits from here rather than force-pushing. |
I don't see the env var being set in either Makefile or CI definitions. Is the parallel flag being used outside local runs?
Take a second look, the v1alpha1 types_test.go has some parallel markers removed that are present in master.
Yep, please do! |
Good catch, I should have verified that more carefully. It's not wired into any Makefile or CI workflow, so I'll drop the change. The
Thanks for pointing that out, I missed that those already had t.Parallel() in master. They're straightforward assertion tests so keeping the existing parallelism makes sense. I'll restore those calls. |
Should we enable it for CI? Seems like a reasonable way to speed up CI runs. Just needs some more wiring. |
The ARGOCD_TEST_PARALLEL env var is not wired into any CI workflow or Makefile, making it dead code. The -parallel flag can be passed directly via go test. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
cb43f35 to
2011517
Compare
Re-adds ARGOCD_TEST_PARALLEL support to hack/test.sh and sets it to 2 in the test-go and test-go-race CI jobs. Ubuntu 24.04 runners have 2 cores, so -parallel=2 matches available CPU for within-package test concurrency. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
6ad9b6e to
a9d8157
Compare
The original refactoring renamed getObj to parseObj, but health_test.go was reverted to upstream master (with getObj). Revert custom_actions_test.go to match, restoring getObj calls. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
gofumpt requires subtest-level t.Parallel() calls to be indented at the function body level. Signed-off-by: Lohit Kolluri <lohitkolluri@gmail.com>
crenshaw-dev
left a comment
There was a problem hiding this comment.
Thanks for your persistence! Looks like CI runtime is ~ the same, so maybe a follow-up would be to continue to tune the parallelism params.
Problem
Issue #27423 requests updating unit tests to run in parallel. Currently, only ~14% of test files in the repo have
t.Parallel(). Addingt.Parallel()to safe tests enables within-package concurrency viago test -parallel Nand can significantly reduce test execution time.Fix
Added
t.Parallel()to safe tests inutil/app/pathandutil/app/discovery:util/app/path/path_test.go:
util/app/discovery/discovery_test.go:
Intentionally left sequential:
t.Chdir()and file system operations that could interfere with parallel tests)Testing
go test ./util/app/path/... ./util/app/discovery/... -count=1passest.TempDir()for unique temporary directoriesRelated Issues
DCO
Signed-off-by: Lohit Kolluri lohitkolluri@gmail.com