Allow setting number of parallel workers to 1

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.
This commit is contained in:
Rafael Mendonça França 2023-08-05 02:10:19 +00:00
parent c1fb418007
commit d1729d5332
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 7 additions and 3 deletions

@ -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

@ -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
@ -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