Skip to content

Commit

Permalink
adding sharding option to run_test.py (#45583)
Browse files Browse the repository at this point in the history
Summary:
Added a sharding option to run_test.py to enable users to run a subset of the many tests. The new `--shard` argument takes in two integer values, `x` and `y`, where the larger value would denote the number of shards and the smaller value would denote which shard to run.

Pull Request resolved: #45583

Reviewed By: malfet

Differential Revision: D24083469

Pulled By: janeyx99

fbshipit-source-id: 1777bd7822c95b3bf37079deff9381c6f8eaf4cc
  • Loading branch information
janeyx99 authored and facebook-github-bot committed Oct 2, 2020
1 parent 3799ba8 commit 6acd7b6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ def parse_args():
nargs='*',
help='additional arguments passed through to unittest, e.g., '
'python run_test.py -i sparse -- TestSparse.test_factory_size_check')
parser.add_argument(
'--shard',
nargs=2,
type=int,
help='runs a shard of the tests (taking into account other selections), e.g., '
'--shard 2 3 will break up the selected tests into 3 shards and run the tests '
'in the 2nd shard (the number of shards will be whichever argument is greater)',
)
return parser.parse_args()


Expand Down Expand Up @@ -517,6 +525,14 @@ def get_selected_tests(options):
last_index = find_test_index(options.last, selected_tests, find_last_index=True)
selected_tests = selected_tests[:last_index + 1]

if options.shard:
assert len(options.shard) == 2, "Unexpected shard format"
assert min(options.shard) > 0, "Shards must be positive numbers"
which_shard, num_shards = options.shard
assert which_shard <= num_shards, "Selected shard must be less or equal that total number of shards"
assert num_shards <= len(selected_tests), f"Number of shards must be less than {len(selected_tests)}"
selected_tests = selected_tests[which_shard - 1 :: num_shards]

selected_tests = exclude_tests(options.exclude, selected_tests)

if sys.platform == 'win32' and not options.ignore_win_blocklist:
Expand Down

0 comments on commit 6acd7b6

Please sign in to comment.