diff options
author | Bogdan <bogdanvlviv@gmail.com> | 2018-12-18 20:25:35 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-12-18 10:25:35 -0800 |
commit | e9f6ce617be2f67b098e6fb689592f70c0009eb2 (patch) | |
tree | fb69f2829c8e70713d4ee15371eda27e98d0362d /railties/test | |
parent | 2f6456cbe1da73c13b37e23720caa8716df85e78 (diff) | |
download | rails-e9f6ce617be2f67b098e6fb689592f70c0009eb2.tar.gz rails-e9f6ce617be2f67b098e6fb689592f70c0009eb2.tar.bz2 rails-e9f6ce617be2f67b098e6fb689592f70c0009eb2.zip |
Add option to set parallel test worker count to the physical core count of the machine (#34735)
* Add option to set parallel test worker count to the physical core count of the machine
Also, use the physical core count of the machine as
the default number of workers, and generate the `test_helper.rb` file
with `parallelize(workers: :number_of_processors)`
Closes #34734
* Ensure that we always test parallel testing
Since #34734 we decided to use the physical core count of the machine as
the default number of workers in the parallel testing, we need to
ensure that some tests use at least 2 workers because we could
run those tests on VM that has only 1 physical core.
It also fixes tests failures on the CI since Travis server we are using
has only one physical core.
See https://travis-ci.org/rails/rails/jobs/469281088#L2352
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/test_runner_test.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 140703e118..55cfda82ea 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -523,6 +523,8 @@ module ApplicationTests end def test_run_in_parallel_with_processes + substitute_arguments_of_parallelize_method("workers: 2, with: :processes") + file_name = create_parallel_processes_test_file app_file "db/schema.rb", <<-RUBY @@ -540,11 +542,7 @@ module ApplicationTests end def test_run_in_parallel_with_threads - app_path("/test/test_helper.rb") do |file_name| - file = File.read(file_name) - file.sub!(/parallelize\(([^\)]*)\)/, "parallelize(\\1, with: :threads)") - File.write(file_name, file) - end + substitute_arguments_of_parallelize_method("workers: 2, with: :threads") file_name = create_parallel_threads_test_file @@ -563,6 +561,8 @@ module ApplicationTests end def test_run_in_parallel_with_unmarshable_exception + substitute_arguments_of_parallelize_method("workers: 2, with: :processes") + file = app_file "test/fail_test.rb", <<-RUBY require "test_helper" class FailTest < ActiveSupport::TestCase @@ -587,6 +587,7 @@ module ApplicationTests end def test_run_in_parallel_with_unknown_object + substitute_arguments_of_parallelize_method("workers: 2, with: :processes") create_scaffold app_file "config/environments/test.rb", <<-RUBY Rails.application.configure do @@ -966,6 +967,14 @@ module ApplicationTests RUBY end + def substitute_arguments_of_parallelize_method(arguments) + app_path("test/test_helper.rb") do |file_name| + file = File.read(file_name) + file.sub!(/parallelize\(([^\)]*)\)/, "parallelize(#{arguments})") + File.write(file_name, file) + end + end + def create_env_test app_file "test/unit/env_test.rb", <<-RUBY require 'test_helper' |