Skip to content

Commit 06e1ba3

Browse files
authored
Merge pull request rails#46720 from ghiculescu/parallel-test-issues
Parallelization test improvements
2 parents 4e3cf1a + 72c9492 commit 06e1ba3

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

activesupport/lib/active_support/test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_order
6868
# The default parallelization method is to fork processes. If you'd like to
6969
# use threads instead you can pass <tt>with: :threads</tt> to the +parallelize+
7070
# method. Note the threaded parallelization does not create multiple
71-
# database and will not work with system tests at this time.
71+
# databases and will not work with system tests.
7272
#
7373
# parallelize(workers: :number_of_processors, with: :threads)
7474
#

railties/test/application/test_runner_test.rb

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -728,27 +728,18 @@ def test_run_in_parallel_with_processes
728728
end
729729
RUBY
730730

731-
output = run_test_command(file_name)
731+
output = run_test_command(file_name, allow_failure: false)
732732

733-
assert_match(/Finished in.*2 runs, 2 assertions/m, output)
733+
assert_match(/Finished in.*2 runs, 2 assertions, 0 failures, 0 errors, 0 skips/m, output)
734734
assert_match %r{Running \d+ tests in parallel using \d+ processes}, output
735735
assert_no_match "create_table(:users)", output
736736
end
737737

738738
def test_parallelization_is_disabled_when_number_of_tests_is_below_threshold
739739
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
740740

741-
file_name = create_parallel_processes_test_file
742-
743-
app_file "db/schema.rb", <<-RUBY
744-
ActiveRecord::Schema.define(version: 1) do
745-
create_table :users do |t|
746-
t.string :name
747-
end
748-
end
749-
RUBY
750-
751-
output = run_test_command(file_name)
741+
file_name = create_parallel_blank_test_file
742+
output = run_test_command(file_name, allow_failure: false)
752743

753744
assert_match %r{Running \d+ tests in a single process}, output
754745
assert_no_match %r{Running \d+ tests in parallel using \d+ processes}, output
@@ -760,18 +751,25 @@ def test_parallel_is_enabled_when_PARALLEL_WORKERS_is_set
760751

761752
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
762753

763-
file_name = app_file "test/unit/parallel_test.rb", <<-RUBY
764-
require "test_helper"
754+
file_name = create_parallel_blank_test_file
755+
output = run_test_command(file_name, allow_failure: false)
765756

766-
class ParallelTest < ActiveSupport::TestCase
767-
def test_verify_test_order
768-
end
769-
end
770-
RUBY
757+
assert_match %r{Running \d+ tests in parallel using 5 processes}, output
758+
ensure
759+
ENV["PARALLEL_WORKERS"] = @old
760+
end
771761

772-
output = run_test_command(file_name)
762+
def test_parallel_is_disabled_when_PARALLEL_WORKERS_is_set_to_1
763+
@old = ENV["PARALLEL_WORKERS"]
764+
ENV["PARALLEL_WORKERS"] = "1"
773765

774-
assert_match %r{Running \d+ tests in parallel using \d+ processes}, output
766+
exercise_parallelization_regardless_of_machine_core_count(with: :processes, threshold: 100)
767+
768+
file_name = create_parallel_blank_test_file
769+
output = run_test_command(file_name, allow_failure: false)
770+
771+
assert_no_match %r{Running \d+ tests in a single process}, output
772+
assert_no_match %r{Running \d+ tests in parallel using \d+ processes}, output
775773
ensure
776774
ENV["PARALLEL_WORKERS"] = @old
777775
end
@@ -807,9 +805,9 @@ def test_run_in_parallel_with_threads
807805
end
808806
RUBY
809807

810-
output = run_test_command(file_name)
808+
output = run_test_command(file_name, allow_failure: false)
811809

812-
assert_match(/Finished in.*2 runs, 2 assertions/m, output)
810+
assert_match(/Finished in.*2 runs, 2 assertions, 0 failures, 0 errors, 0 skips/m, output)
813811
assert_no_match "create_table(:users)", output
814812
end
815813

@@ -1226,6 +1224,16 @@ def test_truth
12261224
RUBY
12271225
end
12281226

1227+
def create_parallel_blank_test_file
1228+
app_file "test/unit/parallel_test.rb", <<-RUBY
1229+
require "test_helper"
1230+
class ParallelTest < ActiveSupport::TestCase
1231+
def test_verify_test_order
1232+
end
1233+
end
1234+
RUBY
1235+
end
1236+
12291237
def create_parallel_processes_test_file
12301238
app_file "test/models/parallel_test.rb", <<-RUBY
12311239
require "test_helper"

0 commit comments

Comments
 (0)