-
Notifications
You must be signed in to change notification settings - Fork 1.7k
tests: parallel batching for packages when running unit tests #17621
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
Draft
parthea
wants to merge
17
commits into
main
Choose a base branch
from
ci-improvements-20260702
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−17
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f2ce4a0
tests: parallel batching for packages when running unit tests
parthea 8cbf92e
Update ci/run_conditional_tests.sh
parthea ef70039
Update ci/run_conditional_tests.sh
parthea e8b90af
Typo
parthea 47e915c
remove 3.15
parthea 492ee5f
Typo
parthea 08933fd
Update ci/run_conditional_tests.sh
parthea c85a266
Update ci/run_conditional_tests.sh
parthea 75e5657
fix TEST_ALL_PACKAGES override
parthea d3a042e
fix presubmit
parthea 4898748
update --cov-fail-under
parthea bbd8144
add weighting
parthea 5ef6f91
syntax
parthea 7b1b6b7
address review feedback
parthea 1aab0d5
Update ci/run_conditional_tests.sh
parthea 4d5e55d
remove weighting
parthea 4e39eeb
set TEST_ALL_PACKAGES to false
parthea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import glob | ||
| import math | ||
| import json | ||
| import sys | ||
|
|
||
| BATCH_SIZE = 10 | ||
|
|
||
| # Packages that take significantly longer to run tests. | ||
| # These will always be assigned to their own dedicated runner. | ||
| ISOLATED_PACKAGES = [ | ||
| "google-cloud-compute", | ||
| "google-cloud-compute-v1beta", | ||
| "google-cloud-dialogflow", | ||
| "google-cloud-dialogflow-cx", | ||
| "google-cloud-retail", | ||
| ] | ||
|
|
||
| def get_batches(): | ||
| """Splits packages into dedicated isolated batches and evenly chunked standard batches.""" | ||
| raw_paths = sorted(glob.glob("packages/*")) | ||
| package_paths = [p for p in raw_paths if os.path.isdir(p)] | ||
|
|
||
| batches = [] | ||
| standard_packages = [] | ||
|
|
||
| for path in package_paths: | ||
| pkg_name = os.path.basename(path) | ||
|
|
||
| if pkg_name in ISOLATED_PACKAGES: | ||
| # Put heavy packages into their own standalone batches immediately | ||
| batches.append([path]) | ||
| else: | ||
| standard_packages.append(path) | ||
|
|
||
| # Chunk the remaining standard packages by BATCH_SIZE | ||
| num_standard_packages = len(standard_packages) | ||
| num_standard_batches = math.ceil(num_standard_packages / BATCH_SIZE) | ||
|
|
||
| if num_standard_batches == 0 and not batches: | ||
| num_standard_batches = 1 | ||
|
|
||
| for i in range(num_standard_batches): | ||
| start_idx = i * BATCH_SIZE | ||
| chunk = standard_packages[start_idx : start_idx + BATCH_SIZE] | ||
| if chunk: | ||
| batches.append(chunk) | ||
|
|
||
| return batches | ||
|
|
||
| def get_batch_indices(): | ||
| """Returns a JSON string of the array of batch indices for GitHub Actions matrix.""" | ||
| batches = get_batches() | ||
| return json.dumps(list(range(len(batches)))) | ||
|
|
||
| def get_batch_slice(batch_index): | ||
| """Returns a space-separated string of unique package paths for a specific batch index.""" | ||
| batches = get_batches() | ||
| if batch_index < 0 or batch_index >= len(batches): | ||
| return "" | ||
| return " ".join(batches[batch_index]) | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) > 1 and sys.argv[1] == "--count": | ||
| print(get_batch_indices()) | ||
| elif len(sys.argv) > 2 and sys.argv[1] == "--slice": | ||
| print(get_batch_slice(int(sys.argv[2]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.