From cb514a1d0487298b5f6daf1032891ee82c8c061e Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:42:27 -0500 Subject: [PATCH] Disable parallel for small test coverage runs `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. --- Library/Homebrew/dev-cmd/tests.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index ec512f72cb..e19945baac 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -3,6 +3,7 @@ require "abstract_command" require "fileutils" +require "hardware" require "system_command" module Homebrew @@ -75,7 +76,13 @@ module Homebrew end end - parallel = false if args.profile + # We use `ParallelTests.last_process?` in `test/spec_helper.rb` to + # handle SimpleCov output but, due to how 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 CPU cores in the execution + # environment. Coverage information isn't saved in that scenario, + # so we disable parallel testing as a workaround in this case. + 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?