Skip to content

Commit

Permalink
Allow setting number of parallel workers to 1
Browse files Browse the repository at this point in the history
In the case that one single test file can't run with more than 1
parallel workers, but the base class has parallelization enabled, we
should still allow the user to set the number of workers to 1.
  • Loading branch information
rafaelfranca committed Aug 5, 2023
1 parent c1fb418 commit d1729d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions activesupport/lib/active_support/test_case.rb
Expand Up @@ -81,8 +81,6 @@ def parallelize(workers: :number_of_processors, with: :processes, threshold: Act
workers = Concurrent.physical_processor_count if workers == :number_of_processors
workers = ENV["PARALLEL_WORKERS"].to_i if ENV["PARALLEL_WORKERS"]

return if workers <= 1

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

Expand Down
Expand Up @@ -53,7 +53,11 @@ def parallelized?
end

def should_parallelize?
ENV["PARALLEL_WORKERS"] || tests_count > threshold
(ENV["PARALLEL_WORKERS"] || tests_count > threshold) && many_workers?
end

def many_workers?
size > 1
end

def tests_count
Expand All @@ -67,6 +71,8 @@ def show_execution_info
def execution_info
if parallelized?
"Running #{tests_count} tests in parallel using #{parallel_executor.size} #{parallelize_with}"
elsif !many_workers?
"Running #{tests_count} tests in a single process"
else
"Running #{tests_count} tests in a single process (parallelization threshold is #{threshold})"
end
Expand Down

0 comments on commit d1729d5

Please sign in to comment.