Skip to content

Commit 4ac4ccb

Browse files
authored
Merge pull request github#5041 from github/parallelize-collection-tests
Parallelize collection tests into 4 shards
2 parents e54c347 + cf134a9 commit 4ac4ccb

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.nil? && !total_shards.nil? && 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)