Skip to content

Commit

Permalink
WIP: Spike using a matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMulhern committed Aug 14, 2024
1 parent 84c048a commit 60579e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [4]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1, 2, 3]
services:
postgres:
image: postgres:15.7
Expand Down Expand Up @@ -96,4 +106,4 @@ jobs:
RAILS_ENV: test
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: postgres
run: bundle exec rake parallel:spec
run: ./bin/ci_spec
15 changes: 15 additions & 0 deletions bin/ci_spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby

# This script is used to run tests in parallel in Github Actions.
# parallel_test test -n 8 --only-group 1,2

CI_RUNNER_PROCESS_COUNT = 2

parallel_tests_is_one_indexed = 1
node_index = ENV['CI_NODE_INDEX'].to_i

groups = "#{node_index * CI_RUNNER_PROCESS_COUNT + parallel_tests_is_one_indexed },#{node_index * CI_RUNNER_PROCESS_COUNT + parallel_tests_is_one_indexed + 1}"

total_parallelism = CI_RUNNER_PROCESS_COUNT * ENV['CI_NODE_TOTAL'].to_i

exec "bundle exec parallel_test ./spec -t rspec -n #{total_parallelism} --only-group #{groups}"

0 comments on commit 60579e8

Please sign in to comment.