Skip to content

Commit

Permalink
feat(maintenance_scripts: discovers_tests_per_worker): split ranges m…
Browse files Browse the repository at this point in the history
…ore even into chunks
  • Loading branch information
actionless committed Aug 23, 2024
1 parent 0c10e2f commit de75f43
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion maintenance_scripts/discover_tests_per_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
RANDOM_SEED: Final = 123


def get_chunks(total: int, num_workers: int) -> list[int]:
base_amount = int(total / num_workers)
result = [base_amount] * num_workers
remaining = total - base_amount * num_workers
remaining_per_worker = math.ceil(remaining / num_workers)
num_workers_to_add_remaning = remaining // remaining_per_worker
for i in range(num_workers_to_add_remaning):
result[i] += remaining_per_worker
return result


def do_stuff(num_workers: int, worker_idx: int) -> None:
if worker_idx >= num_workers:
raise RuntimeError
Expand All @@ -20,7 +31,7 @@ def do_stuff(num_workers: int, worker_idx: int) -> None:
]
random.seed(RANDOM_SEED)
random.shuffle(tests)
per_worker = math.ceil(len(tests) / num_workers)
per_worker = get_chunks(len(tests), num_workers)[worker_idx]
tests_start_idx = worker_idx * per_worker
tests_end_idx = min(len(tests), tests_start_idx + per_worker)

Expand Down

0 comments on commit de75f43

Please sign in to comment.