aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-07-17 12:08:41 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-07-17 12:08:41 -0700
commitc64bff2c87ebf363703c63ecd4a96d56a1a78364 (patch)
tree0d1e6a0adb87aa848bdf7b473185e578f701ac3d /actionpack
parent932386be8a9c0f60c7bb078261c5433aeccb3284 (diff)
downloadrails-c64bff2c87ebf363703c63ecd4a96d56a1a78364.tar.gz
rails-c64bff2c87ebf363703c63ecd4a96d56a1a78364.tar.bz2
rails-c64bff2c87ebf363703c63ecd4a96d56a1a78364.zip
[EXPERIMENTAL] run actionpack tests in parallel
only on forking systems though. Feel free to revert this if it causes problems.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/abstract_unit.rb57
1 files changed, 57 insertions, 0 deletions
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