Skip
Arish's avatar

7. Parallel Testing


Matrix Strategy

Run tests in parallel across configurations:

yaml
1jobs:
2  test:
3    runs-on: ubuntu-latest
4    strategy:
5      matrix:
6        ruby: ['3.1', '3.2', '3.3']
7        database: ['postgres', 'mysql']
8    
9    steps:
10      - uses: ruby/setup-ruby@v1
11        with:
12          ruby-version: ${{ matrix.ruby }}

Parallel Test Execution

Split tests across multiple runners:

yaml
1jobs:
2  test:
3    runs-on: ubuntu-latest
4    strategy:
5      matrix:
6        ci_node_total: [4]
7        ci_node_index: [0, 1, 2, 3]
8    
9    steps:
10      - name: Run tests
11        env:
12          CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
13          CI_NODE_INDEX: ${{ matrix.ci_node_index }}
14        run: |
15          bundle exec rspec $(
16            circleci tests glob "spec/**/*_spec.rb" |
17            circleci tests split --split-by=timings
18          )

Using parallel_tests Gem

ruby
1# Gemfile
2gem 'parallel_tests', group: :test
yaml
1- name: Run parallel tests
2  run: bundle exec parallel_rspec spec/

Fail Fast

yaml
1strategy:
2  fail-fast: true  # Stop all on first failure
3  matrix:
4    ruby: ['3.1', '3.2']