-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
test: Parallelize package tests in high-cost packages. #7126
test: Parallelize package tests in high-cost packages. #7126
Conversation
Looks like there's a data race occurring under |
15cabfd
to
c2e0bcd
Compare
ℹ️ Found the culprits! In both cases, the offending tests with race conditions were cases where the tests were modifying package variables of some sort. The two sets of cases were:
|
dd0f3ac
to
673cefc
Compare
ℹ️ Looks like I've got a few more intermittent failures in the EDIT: I think we're stable once more. There was a timeout value that I'd lowered, and the slow GH Actions runner was causing the test to occasionally time out unexpectedly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @philipaconrad! The comments about why tests are excluded from parallel execution are helpful. The tests are green so this LGTM.
This commit adds `t.Parallel()` calls to the beginning of many tests across several Go packages in OPA. The slowest packages (taking ~10s or more) have been instrumented where possible as a proof-of-concept. On a machine with many cores, the tests now will complete as fast as the slowest test per package, instead of the sum of all the tests in a particular package. Background: Go runs tests across different packages in parallel, but will run all tests *within* a package sequentially. By adding `t.Parallel()` to tests that support it, we are telling the test-runner that it is safe to run that test in parallel with any other tests. Signed-off-by: Philip Conrad <[email protected]>
This commit fixes a data race that could occur in the `server` package tests, because 3x tests were modifying package variables under `internal/version`. These tests now run sequentially, and are not included in the parallel test set. Signed-off-by: Philip Conrad <[email protected]>
Two tests in this package modified a package variable directly, and as such cannot be safely run in parallel with each other or any other tests in the package. Signed-off-by: Philip Conrad <[email protected]>
This commit wraps up a large batch of fairly mechanical refactorings to add t.Parallel() annotations to almost every test under `topdown`. The tests that could not be safely parallelized now have explicit warning comments on them describing why they are not safe to run in parallel. Signed-off-by: Philip Conrad <[email protected]>
This commit bundles up test parallelization changes for the `storage/disk` package, dramatically reducing its execution time. Signed-off-by: Philip Conrad <[email protected]>
Signed-off-by: Philip Conrad <[email protected]>
This commit includes a bundle of t.Parallel refactoring changes for the `rego` package, including a timer-related bugfix, and a slight change on a cancellation test to reduce its overall cost during test runs (the logic is preserved, but the mandatory timeouts are lower now). Signed-off-by: Philip Conrad <[email protected]>
Signed-off-by: Philip Conrad <[email protected]>
1ce32da
to
9a3ff47
Compare
Rebasing through the Github UI, and then will merge when green. |
What changed?
This commit adds
t.Parallel()
calls to the beginning of many tests across several Go packages in OPA. Most of the slowest packages (those taking ~10s or more) have been instrumented where possible as a proof-of-concept. On a machine with many cores, the tests now will complete as fast as the slowest test per package, instead of the sum of all the tests in a particular package.Motivation (Why these changes?)
make test
locally, especially on multicore systemsserver
,topdown/*
,plugins/*
,download
, etc.Background Notes on
t.Parallel
Go runs tests across different packages in parallel, but will run all tests within a package sequentially. By adding
t.Parallel()
to tests that support it, we are telling the test-runner that it is safe to run that test in parallel with any other tests.Adding
t.Parallel
at the top of a test marks that test as safe to run in parallel with other tests, but if it has sub-tests, they are run sequentially by default. In some places, I've added thet.Parallel
annotation to sub-tests as well, which allows table-driven tests to benefit from available parallelism as well.TODOs
Some remaining targets for parallelizing:
topdown/
:: Original run time: ~1 minute. ➡️ New run time: ~30s on a multicore machine.tester/
:: Run time: ~1 minute.storage/disk/
:: Original run time: ~25-30s. ➡️ New run time: ~5-7s.rego/
takes about 10 seconds.