Conversation
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.
There was a problem hiding this comment.
Pull request overview
This PR parallelizes collection tests across 4 shards to reduce wall-clock time by approximately 4x. The sharding is implemented using modular arithmetic on alphabetically sorted collections, where each of the 4 GitHub Actions matrix jobs tests roughly 25% of the ~100 collections.
Changes:
- Added sharding logic to split collection tests across parallel jobs
- Modified GitHub Actions workflow to create 4 separate collection test jobs
- Implemented deterministic shard assignment using alphabetical sorting and modulo operation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/collections_test_helper.rb |
Added shard_collections function to filter collections based on shard environment variables |
.github/workflows/test.yml |
Replaced single collections matrix entry with 4 sharded entries and passed shard environment variables |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
test/collections_test_helper.rb
Outdated
| shard = ENV["COLLECTION_SHARD"]&.to_i | ||
| total_shards = ENV["COLLECTION_TOTAL_SHARDS"]&.to_i | ||
|
|
||
| return all_collections unless shard && total_shards && total_shards > 1 |
There was a problem hiding this comment.
The condition shard && total_shards && total_shards > 1 will fail when shard is 0 because 0 is falsy in Ruby. This means shard 0 (the first shard in the matrix) will incorrectly test all collections instead of just every 4th collection starting at index 0. The condition should check for nil explicitly instead: !shard.nil? && !total_shards.nil? && total_shards > 1.
There was a problem hiding this comment.
Fixed in 198d465 — switched to explicit nil checks: !shard.nil? && !total_shards.nil? && total_shards > 1. This also avoids the falsy-zero bug for shard 0. Thanks for the catch!
Summary
Changes
test/collections_test_helper.rb: Addshard_collectionsfunction that uses modular arithmetic on alphabetically sorted collections. Modifiedcollectionsto apply sharding whenCOLLECTION_SHARDandCOLLECTION_TOTAL_SHARDSenv vars are set.github/workflows/test.yml: Replace singlecollectionsmatrix entry with 4 sharded entries (shard 0-3). Pass shard env vars to the test stepHow sharding works
Collections are sorted alphabetically for deterministic assignment. Each collection is assigned to shard
index % total_shards. For example with 4 shards:Notes
topicsandalljobs are unaffected