From c64bff2c87ebf363703c63ecd4a96d56a1a78364 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 17 Jul 2014 12:08:41 -0700 Subject: [EXPERIMENTAL] run actionpack tests in parallel only on forking systems though. Feel free to revert this if it causes problems. --- actionpack/test/abstract_unit.rb | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 1c143a0f8c..472ac60a13 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -15,6 +15,10 @@ silence_warnings do Encoding.default_external = "UTF-8" end +require 'drb' +require 'drb/unix' +require 'tempfile' + require 'active_support/testing/autorun' require 'abstract_controller' require 'action_controller' @@ -105,6 +109,7 @@ end module ActiveSupport class TestCase include ActionDispatch::DrawOnce + parallelize_me! end end @@ -432,3 +437,55 @@ end def jruby_skip(message = '') skip message if defined?(JRUBY_VERSION) end + +class ForkingExecutor + class Server + include DRb::DRbUndumped + + def initialize + @queue = Queue.new + end + + def record reporter, result + reporter.synchronize { reporter.record result } + end + + def << o; @queue << o; end + def pop; @queue.pop; end + end + + def initialize size + @size = size + @queue = Server.new + file = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname('tests', 'fd') + @url = "drbunix://#{file}" + @pool = nil + DRb.start_service @url, @queue + end + + def << work; @queue << work; end + + def shutdown + pool = @size.times.map { + fork { + DRb.stop_service + DRb.start_service + queue = DRbObject.new_with_uri @url + while job = queue.pop + klass = job[0] + method = job[1] + reporter = job[2] + result = Minitest.run_one_method klass, method + queue.record reporter, result + end + } + } + @size.times { @queue << nil } + pool.each { |pid| Process.waitpid pid } + end +end + +if ActiveSupport::Testing::Isolation.forking_env? + # Use N processes (N defaults to 4) + Minitest.parallel_executor = ForkingExecutor.new((ENV['N'] || 4).to_i) +end -- cgit v1.2.3