Skip to content

Commit

Permalink
Disable parallel for small test coverage runs
Browse files Browse the repository at this point in the history
`brew tests --coverage` can fail to produce coverage information when
run on a small number of tests (e.g., `--only utils/curl`). We use `ParallelTests::last_process?` in `tests/spec_helper.rb` to handle
the SimpleCov output but due to the way the method is implemented, it
doesn't work as expected if the number of processes is greater than
one but lower than the number of cores. I tried to address this
through changes to  `spec_helper.rb` and/or changes to `ParallelTests`
but didn't meet with any success.

This works around the issue by disabling parallel test execution when
the `--coverage` option is used and the number of files to be tested
is lower than the number of CPU cores. I've been using this workaround
for months and it works as expected on my machine.
  • Loading branch information
samford committed Jan 9, 2025
1 parent 6aac197 commit 42a2433
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "abstract_command"
require "fileutils"
require "hardware"
require "system_command"

module Homebrew
Expand Down Expand Up @@ -75,7 +76,7 @@ def run
end
end

parallel = false if args.profile
parallel = false if args.profile || (args.coverage? && files.length < Hardware::CPU.cores)

parallel_rspec_log_name = "parallel_runtime_rspec"
parallel_rspec_log_name = "#{parallel_rspec_log_name}.generic" if args.generic?
Expand Down

0 comments on commit 42a2433

Please sign in to comment.