Testing: parallel tests
This app's RSpec suite has 205 spec files and 1,219 examples. It runs in one process in about 1 minute 19 seconds. The course asks whether running it in parallel would help. It reads Minitest's built-in ActiveSupport::TestCase.parallelize and explains why it has nothing to run here. It then covers the separate parallel_tests gem for RSpec and how it groups spec files by size or runtime. The TEST_ENV_NUMBER database convention follows, then a cost analysis and a small plain-Ruby load-balancing challenge.
What you'll learn
- ✓How Minitest's parallelize works with processes, threads and its 50-test threshold
- ✓Why rspec-core has no parallel runner and what the parallel_tests gem adds
- ✓How parallel_tests groups whole spec files by filesize or runtime
- ✓The TEST_ENV_NUMBER convention for one test database per process
- ✓How to weigh fixed costs like file loading and database setup against time saved
This app's spec suite, timed, runs in one process
That's this app's spec suite, run for this course: 205 spec files and 1,219 examples. RSpec reports 1 minute 19.03 seconds of run time. Loading the files beforehand, requiring every spec, factory and support file before a single example runs, took another 2.87 seconds. Every number in this course…
Read the full lesson free →Curriculum
7 lessonsThis app's spec suite, timed, runs in one process
Times this app's 205-file, 1,219-example RSpec suite running in one process and notes CI never runs it.
Minitest's built-in parallelize: installed, but nothing to run here
Reads Minitest's parallelize source, its process and thread modes, the 50-test threshold, and why this app cannot use it.
RSpec's answer is a separate gem, not something built in
Shows that rspec-core has no parallel runner and introduces the separate parallel_tests gem and its parallel_rspec command.
How parallel_tests decides which files go to which process
Explains how parallel_tests groups whole spec files by filesize or runtime, unlike Minitest's split by test method.
TEST_ENV_NUMBER: one database per process
Covers the TEST_ENV_NUMBER convention for one database per process and why this app's database.yml lacks it.
Does parallelizing this app's suite help, at its current size?
Compares this suite's run time with the gem's benchmark and weighs the fixed costs of loading and database setup.
Putting it together: two mechanisms, one measurement
Recaps both mechanisms and their sources, then offers a plain-Ruby challenge spreading uneven work across a fixed set of workers.