Skip to content

Commit c47b44b

Browse files
committed
Parallelize collection tests into 4 shards
Split collection tests across 4 parallel matrix jobs using modular arithmetic on alphabetically sorted collection names. Each shard tests roughly 25 collections instead of all ~100, reducing wall-clock time by ~4x for collection testing. Sharding is controlled by COLLECTION_SHARD and COLLECTION_TOTAL_SHARDS env vars, making it easy to adjust the shard count in the future.
1 parent 67774fb commit c47b44b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,21 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
test_type:
20-
- collections
21-
- topics
22-
- all
19+
include:
20+
- test_type: topics
21+
- test_type: collections
22+
shard: 0
23+
total_shards: 4
24+
- test_type: collections
25+
shard: 1
26+
total_shards: 4
27+
- test_type: collections
28+
shard: 2
29+
total_shards: 4
30+
- test_type: collections
31+
shard: 3
32+
total_shards: 4
33+
- test_type: all
2334
runs-on: ubuntu-latest
2435
steps:
2536
- uses: actions/checkout@v6.0.1
@@ -58,3 +69,5 @@ jobs:
5869
TOPIC_FILES: ${{ steps.topics.outputs.changed }}
5970
COLLECTION_FILES: ${{ steps.collections.outputs.changed }}
6071
TEST_ALL_FILES: ${{ steps.all.outputs.changed }}
72+
COLLECTION_SHARD: ${{ matrix.shard }}
73+
COLLECTION_TOTAL_SHARDS: ${{ matrix.total_shards }}

test/collections_test_helper.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ def dirs_to_test
5353
end
5454

5555
def collections
56-
collection_dirs.map { |dir_path| File.basename(dir_path) }
56+
all = collection_dirs.map { |dir_path| File.basename(dir_path) }
57+
shard_collections(all)
58+
end
59+
60+
def shard_collections(all_collections)
61+
shard = ENV["COLLECTION_SHARD"]&.to_i
62+
total_shards = ENV["COLLECTION_TOTAL_SHARDS"]&.to_i
63+
64+
return all_collections unless shard && total_shards && total_shards > 1
65+
66+
# Sort alphabetically for deterministic sharding
67+
sorted = all_collections.sort
68+
sorted.select.with_index { |_, i| i % total_shards == shard }
5769
end
5870

5971
def items_for_collection(collection)

0 commit comments

Comments
 (0)