aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt4
-rw-r--r--railties/test/application/test_runner_test.rb19
2 files changed, 16 insertions, 7 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt
index c06cd525d7..47b4cf745c 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt
@@ -5,9 +5,9 @@ require 'rails/test_help'
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
<% if defined?(JRUBY_VERSION) || Gem.win_platform? -%>
- parallelize(workers: 2, with: :threads)
+ parallelize(workers: :number_of_processors, with: :threads)
<%- else -%>
- parallelize(workers: 2)
+ parallelize(workers: :number_of_processors)
<% end -%>
<% unless options[:skip_active_record] -%>
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'