Skip to content

Commit debbbbc

Browse files
committed
Remove mechanism to disable test parallelization when runnin gonly 1 test
rails#42761 made the old system of disable paralleling testing when only one test file was included obsolete.
1 parent 76694cc commit debbbbc

File tree

4 files changed

+6
-66
lines changed

4 files changed

+6
-66
lines changed

activesupport/lib/active_support.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,8 @@ def self.eager_load!
8787
end
8888

8989
cattr_accessor :test_order # :nodoc:
90-
cattr_accessor :test_parallelization_disabled, default: false # :nodoc:
9190
cattr_accessor :test_parallelization_threshold, default: 50 # :nodoc:
9291

93-
def self.disable_test_parallelization!
94-
self.test_parallelization_disabled = true unless ENV["PARALLEL_WORKERS"]
95-
end
96-
9792
def self.cache_format_version
9893
Cache.format_version
9994
end

activesupport/lib/active_support/test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def parallelize(workers: :number_of_processors, with: :processes, threshold: Act
8080
workers = Concurrent.physical_processor_count if workers == :number_of_processors
8181
workers = ENV["PARALLEL_WORKERS"].to_i if ENV["PARALLEL_WORKERS"]
8282

83-
return if workers <= 1 || ActiveSupport.test_parallelization_disabled
83+
return if workers <= 1
8484

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

railties/lib/rails/test_unit/runner.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def load_tests(argv)
4747

4848
tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
4949
tests.exclude(default_test_exclude_glob) if patterns.empty?
50-
# Disable parallel testing if there's only one test file to run.
51-
ActiveSupport.disable_test_parallelization! if tests.size <= 1
5250
tests.to_a.each { |path| require File.expand_path(path) }
5351
end
5452

railties/test/application/test_runner_test.rb

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def test_run_in_parallel_with_processes
571571
assert_no_match "create_table(:users)", output
572572
end
573573

574-
def test_avoid_parallelizing_when_number_of_tests_is_below_threshold
574+
def test_parallelization_is_disabled_when_number_of_tests_is_below_threshold
575575
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
576576

577577
file_name = create_parallel_processes_test_file
@@ -590,72 +590,24 @@ def test_avoid_parallelizing_when_number_of_tests_is_below_threshold
590590
assert_no_match %r{Running \d+ tests in parallel using \d+ processes}, output
591591
end
592592

593-
def test_parallel_is_disabled_when_single_file_is_run
594-
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
595-
596-
file_name = app_file "test/unit/parallel_test.rb", <<-RUBY
597-
require "test_helper"
598-
599-
class ParallelTest < ActiveSupport::TestCase
600-
def test_verify_test_order
601-
puts "Test parallelization disabled: \#{ActiveSupport.test_parallelization_disabled}"
602-
end
603-
end
604-
RUBY
605-
606-
output = run_test_command(file_name)
607-
608-
assert_match "Test parallelization disabled: true", output
609-
end
610-
611-
def test_parallel_is_enabled_when_multiple_files_are_run
612-
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
613-
614-
file_1 = app_file "test/unit/parallel_test_first.rb", <<-RUBY
615-
require "test_helper"
616-
617-
class ParallelTestFirst < ActiveSupport::TestCase
618-
def test_verify_test_order
619-
puts "Test parallelization disabled (file 1): \#{ActiveSupport.test_parallelization_disabled}"
620-
end
621-
end
622-
RUBY
623-
624-
file_2 = app_file "test/unit/parallel_test_second.rb", <<-RUBY
625-
require "test_helper"
626-
627-
class ParallelTestSecond < ActiveSupport::TestCase
628-
def test_verify_test_order
629-
puts "Test parallelization disabled (file 2): \#{ActiveSupport.test_parallelization_disabled}"
630-
end
631-
end
632-
RUBY
633-
634-
output = run_test_command([file_1, file_2].join(" "))
635-
636-
assert_match "Test parallelization disabled (file 1): false", output
637-
assert_match "Test parallelization disabled (file 2): false", output
638-
end
639-
640593
def test_parallel_is_enabled_when_PARALLEL_WORKERS_is_set
641594
@old = ENV["PARALLEL_WORKERS"]
642595
ENV["PARALLEL_WORKERS"] = "5"
643596

644-
exercise_parallelization_regardless_of_machine_core_count(with: :processes, force: false)
597+
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
645598

646599
file_name = app_file "test/unit/parallel_test.rb", <<-RUBY
647600
require "test_helper"
648601
649602
class ParallelTest < ActiveSupport::TestCase
650603
def test_verify_test_order
651-
puts "Test parallelization disabled: \#{ActiveSupport.test_parallelization_disabled}"
652604
end
653605
end
654606
RUBY
655607

656608
output = run_test_command(file_name)
657609

658-
assert_match "Test parallelization disabled: false", output
610+
assert_match %r{Running \d+ tests in parallel using \d+ processes}, output
659611
ensure
660612
ENV["PARALLEL_WORKERS"] = @old
661613
end
@@ -1160,18 +1112,13 @@ class ParallelTest < ActiveSupport::TestCase
11601112
RUBY
11611113
end
11621114

1163-
def exercise_parallelization_regardless_of_machine_core_count(with:, force: true, threshold: 0)
1164-
file_content = ERB.new(<<-ERB, trim_mode: "-").result_with_hash(with: with.to_s, force: force)
1115+
def exercise_parallelization_regardless_of_machine_core_count(with:, threshold: 0)
1116+
file_content = ERB.new(<<-ERB, trim_mode: "-").result_with_hash(with: with.to_s)
11651117
ENV["RAILS_ENV"] ||= "test"
11661118
require_relative "../config/environment"
11671119
require "rails/test_help"
11681120
11691121
class ActiveSupport::TestCase
1170-
<%- if force -%>
1171-
# Force parallelization, even with single files
1172-
ActiveSupport.test_parallelization_disabled = false
1173-
<%- end -%>
1174-
11751122
# Run tests in parallel with specified workers
11761123
parallelize(workers: 2, with: :<%= with %>, threshold: #{threshold})
11771124

0 commit comments

Comments
 (0)