-
Notifications
You must be signed in to change notification settings - Fork 16
Parallelize tests for faster PR turnaround time #372
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
Merged
dphuang2
merged 4 commits into
main
from
dhuang/pro-437-parallelize-tests-for-faster-pr-turnaround-time
Dec 14, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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,80 @@ | ||
| #!/usr/bin/env bash | ||
| # Script to run a shard of tests for parallel CI execution | ||
| # Usage: ./scripts/run_sharded_tests.sh <shard> <total_shards> [--dry-run] | ||
| # Example: ./scripts/run_sharded_tests.sh 1 4 | ||
| # Example: ./scripts/run_sharded_tests.sh 1 4 --dry-run | ||
|
|
||
| set -e | ||
|
|
||
| SHARD=${1:-1} | ||
| TOTAL_SHARDS=${2:-4} | ||
| DRY_RUN=${3:-""} | ||
|
|
||
| if [ "$SHARD" -lt 1 ] || [ "$SHARD" -gt "$TOTAL_SHARDS" ]; then | ||
| echo "Error: Shard must be between 1 and $TOTAL_SHARDS" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Collect all test files, excluding ignored ones | ||
| TEST_FILES=$(find tests -name "test_*.py" \ | ||
| ! -path "tests/test_batch_evaluation.py" \ | ||
| ! -path "tests/pytest/test_frozen_lake.py" \ | ||
| ! -path "tests/pytest/test_lunar_lander.py" \ | ||
| ! -path "tests/pytest/test_tau_bench_airline.py" \ | ||
| ! -path "tests/pytest/test_apps_coding.py" \ | ||
| ! -path "tests/test_tau_bench_airline_smoke.py" \ | ||
| ! -path "tests/pytest/test_svgbench.py" \ | ||
| ! -path "tests/pytest/test_livesvgbench.py" \ | ||
| ! -path "tests/remote_server/test_remote_fireworks.py" \ | ||
| ! -path "tests/remote_server/test_remote_fireworks_propagate_status.py" \ | ||
| ! -path "tests/logging/test_elasticsearch_direct_http_handler.py" \ | ||
| | sort) | ||
|
|
||
| # Count total files | ||
| TOTAL_FILES=$(echo "$TEST_FILES" | wc -l | tr -d ' ') | ||
|
|
||
| # Calculate start and end line numbers for this shard (1-indexed for sed) | ||
| FILES_PER_SHARD=$(( (TOTAL_FILES + TOTAL_SHARDS - 1) / TOTAL_SHARDS )) | ||
| START_LINE=$(( (SHARD - 1) * FILES_PER_SHARD + 1 )) | ||
| END_LINE=$(( START_LINE + FILES_PER_SHARD - 1 )) | ||
| if [ $END_LINE -gt $TOTAL_FILES ]; then | ||
| END_LINE=$TOTAL_FILES | ||
| fi | ||
|
|
||
| # Get files for this shard using sed | ||
| SHARD_FILES=$(echo "$TEST_FILES" | sed -n "${START_LINE},${END_LINE}p") | ||
| SHARD_COUNT=$(echo "$SHARD_FILES" | grep -c . || echo 0) | ||
|
|
||
| echo "========================================" | ||
| echo "Running shard $SHARD of $TOTAL_SHARDS" | ||
| echo "========================================" | ||
| echo "Total test files: $TOTAL_FILES" | ||
| echo "Files per shard: ~$FILES_PER_SHARD" | ||
| echo "Files in this shard: $SHARD_COUNT" | ||
| echo "Line range: $START_LINE to $END_LINE" | ||
| echo "----------------------------------------" | ||
| echo "Files:" | ||
| echo "$SHARD_FILES" | while read -r f; do | ||
| echo " $f" | ||
| done | ||
| echo "----------------------------------------" | ||
|
|
||
| if [ "$SHARD_COUNT" -eq 0 ] || [ -z "$SHARD_FILES" ]; then | ||
| echo "No files in this shard, skipping tests" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Check if --dry-run flag is passed | ||
| if [ "$DRY_RUN" = "--dry-run" ]; then | ||
| echo "Dry run mode - not executing tests" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Run tests for this shard | ||
| # shellcheck disable=SC2086 | ||
| exec pytest \ | ||
| -n auto \ | ||
| --ignore=eval_protocol/benchmarks/ \ | ||
| --ignore=eval_protocol/quickstart/ \ | ||
| -v --durations=10 \ | ||
| $SHARD_FILES |
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.
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.
Bug: Exception handler misses AttributeError from dict method
The try/except block catches
json.JSONDecodeErrorandTypeError, but if the API returns valid JSON that isn't a dictionary (like an integer"123"or a list"[]"), calling.get()on the parsed value raisesAttributeError, which escapes the handler. AddingAttributeErrorto the except clause would make the error handling complete.