Remove mechanism to disable test parallelization when runnin gonly 1 test
#42761 made the old system of disable paralleling testing when only one test file was included obsolete.
This commit is contained in:
parent
71cbc9150f
commit
a29884d733
@ -87,13 +87,8 @@ def self.eager_load!
|
||||
end
|
||||
|
||||
cattr_accessor :test_order # :nodoc:
|
||||
cattr_accessor :test_parallelization_disabled, default: false # :nodoc:
|
||||
cattr_accessor :test_parallelization_threshold, default: 50 # :nodoc:
|
||||
|
||||
def self.disable_test_parallelization!
|
||||
self.test_parallelization_disabled = true unless ENV["PARALLEL_WORKERS"]
|
||||
end
|
||||
|
||||
def self.cache_format_version
|
||||
Cache.format_version
|
||||
end
|
||||
|
@ -80,7 +80,7 @@ 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 || ActiveSupport.test_parallelization_disabled
|
||||
return if workers <= 1
|
||||
|
||||
Minitest.parallel_executor = ActiveSupport::Testing::ParallelizeExecutor.new(size: workers, with: with, threshold: threshold)
|
||||
end
|
||||
|
@ -47,8 +47,6 @@ def load_tests(argv)
|
||||
|
||||
tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
|
||||
tests.exclude(default_test_exclude_glob) if patterns.empty?
|
||||
# Disable parallel testing if there's only one test file to run.
|
||||
ActiveSupport.disable_test_parallelization! if tests.size <= 1
|
||||
tests.to_a.each { |path| require File.expand_path(path) }
|
||||
end
|
||||
|
||||
|
@ -571,7 +571,7 @@ def test_run_in_parallel_with_processes
|
||||
assert_no_match "create_table(:users)", output
|
||||
end
|
||||
|
||||
def test_avoid_parallelizing_when_number_of_tests_is_below_threshold
|
||||
def test_parallelization_is_disabled_when_number_of_tests_is_below_threshold
|
||||
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
|
||||
|
||||
file_name = create_parallel_processes_test_file
|
||||
@ -590,72 +590,24 @@ def test_avoid_parallelizing_when_number_of_tests_is_below_threshold
|
||||
assert_no_match %r{Running \d+ tests in parallel using \d+ processes}, output
|
||||
end
|
||||
|
||||
def test_parallel_is_disabled_when_single_file_is_run
|
||||
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
|
||||
|
||||
file_name = app_file "test/unit/parallel_test.rb", <<-RUBY
|
||||
require "test_helper"
|
||||
|
||||
class ParallelTest < ActiveSupport::TestCase
|
||||
def test_verify_test_order
|
||||
puts "Test parallelization disabled: \#{ActiveSupport.test_parallelization_disabled}"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
output = run_test_command(file_name)
|
||||
|
||||
assert_match "Test parallelization disabled: true", output
|
||||
end
|
||||
|
||||
def test_parallel_is_enabled_when_multiple_files_are_run
|
||||
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
|
||||
|
||||
file_1 = app_file "test/unit/parallel_test_first.rb", <<-RUBY
|
||||
require "test_helper"
|
||||
|
||||
class ParallelTestFirst < ActiveSupport::TestCase
|
||||
def test_verify_test_order
|
||||
puts "Test parallelization disabled (file 1): \#{ActiveSupport.test_parallelization_disabled}"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
file_2 = app_file "test/unit/parallel_test_second.rb", <<-RUBY
|
||||
require "test_helper"
|
||||
|
||||
class ParallelTestSecond < ActiveSupport::TestCase
|
||||
def test_verify_test_order
|
||||
puts "Test parallelization disabled (file 2): \#{ActiveSupport.test_parallelization_disabled}"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
output = run_test_command([file_1, file_2].join(" "))
|
||||
|
||||
assert_match "Test parallelization disabled (file 1): false", output
|
||||
assert_match "Test parallelization disabled (file 2): false", output
|
||||
end
|
||||
|
||||
def test_parallel_is_enabled_when_PARALLEL_WORKERS_is_set
|
||||
@old = ENV["PARALLEL_WORKERS"]
|
||||
ENV["PARALLEL_WORKERS"] = "5"
|
||||
|
||||
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
|
||||
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
|
||||
|
||||
file_name = app_file "test/unit/parallel_test.rb", <<-RUBY
|
||||
require "test_helper"
|
||||
|
||||
class ParallelTest < ActiveSupport::TestCase
|
||||
def test_verify_test_order
|
||||
puts "Test parallelization disabled: \#{ActiveSupport.test_parallelization_disabled}"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
output = run_test_command(file_name)
|
||||
|
||||
assert_match "Test parallelization disabled: false", output
|
||||
assert_match %r{Running \d+ tests in parallel using \d+ processes}, output
|
||||
ensure
|
||||
ENV["PARALLEL_WORKERS"] = @old
|
||||
end
|
||||
@ -1160,18 +1112,13 @@ class ParallelTest < ActiveSupport::TestCase
|
||||
RUBY
|
||||
end
|
||||
|
||||
def exercise_parallelization_regardless_of_machine_core_count(with:, force: true, threshold: 0)
|
||||
file_content = ERB.new(<<-ERB, trim_mode: "-").result_with_hash(with: with.to_s, force: force)
|
||||
def exercise_parallelization_regardless_of_machine_core_count(with:, threshold: 0)
|
||||
file_content = ERB.new(<<-ERB, trim_mode: "-").result_with_hash(with: with.to_s)
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../config/environment"
|
||||
require "rails/test_help"
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
<%- if force -%>
|
||||
# Force parallelization, even with single files
|
||||
ActiveSupport.test_parallelization_disabled = false
|
||||
<%- end -%>
|
||||
|
||||
# Run tests in parallel with specified workers
|
||||
parallelize(workers: 2, with: :<%= with %>, threshold: #{threshold})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user