Skip to content

Commit

Permalink
Parallel tests with :number_of_processors use cgroups-aware processor…
Browse files Browse the repository at this point in the history
… count

(We already require concurrent-ruby 1.3.1+ with support for this.)

References:
* rails@f719787
* ruby-concurrency/concurrent-ruby#1038
  • Loading branch information
jeremy committed Nov 14, 2024
1 parent 8a7d2c1 commit 676d8c2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions activesupport/lib/active_support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ def test_order
# number of tests to run is above the +threshold+ param. The default value is
# 50, and it's configurable via +config.active_support.test_parallelization_threshold+.
def parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold)
workers = Concurrent.processor_count if workers == :number_of_processors
workers = ENV["PARALLEL_WORKERS"].to_i if ENV["PARALLEL_WORKERS"]
case
when ENV["PARALLEL_WORKERS"]
workers = ENV["PARALLEL_WORKERS"].to_i
when workers == :number_of_processors
workers = (Concurrent.available_processor_count || Concurrent.processor_count).floor
end

Minitest.parallel_executor = ActiveSupport::Testing::ParallelizeExecutor.new(size: workers, with: with, threshold: threshold)
end
Expand Down

0 comments on commit 676d8c2

Please sign in to comment.