Optimizing Rails CI with parallel_tests
By Aldin Rozario
In our previous blog post on speeding up test suites with parallel_tests, we explored how the gem can significantly speed up test suites locally. Now let’s take it further — implementing parallel_tests in a CI environment.
Why Parallel Tests in CI?
Running tests in parallel in CI provides three major benefits:
- Faster feedback — developers get results sooner
- Scalability — handles growing test suites efficiently
- Cost efficiency — better utilization of CI resources
The Single Job Approach
The single job approach with GitHub Actions is the most straightforward way to get started. It requires:
- Multiple databases using
rake parallel:setup - Utilization of VM resources
- Simplified setup compared to matrix strategies
Step-by-Step Setup
1. Add parallel_tests to your Gemfile
group :test do
gem 'parallel_tests'
end
2. Configure database.yml
Your test database configuration needs to support multiple databases:
test:
database: myapp_test<%= ENV['TEST_ENV_NUMBER'] %>
3. GitHub Actions Configuration
Set up your workflow with PostgreSQL service, Ruby setup, bundler caching, and parallel test execution. Use rake parallel:setup to create multiple test databases (e.g., myapp_test1, myapp_test2).
4. Run parallel tests
bundle exec rake parallel:spec
Potential Challenges
- Resource constraints — set
PARALLEL_TEST_PROCESSORSto 80-90% of available cores - Database conflicts — solved by
parallel:setupcreating isolated databases - Over-provisioning processes — too many processes causes context switching overhead
Note that GitHub’s free plan provides only 2 cores, so adjust your parallelism accordingly.
Conclusion
With the right configuration, parallel_tests can dramatically reduce your CI pipeline duration, giving your team faster feedback and more productive development cycles.