diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-06-19 17:08:15 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-06-19 17:08:23 -0700 |
commit | 265f13495fb326bd2e6a5bc9cae7e297e42893d0 (patch) | |
tree | ca4c06a89e2bd9bbe097d9b09d2d07d1d7e25274 | |
parent | a7e715e102ae1e905e69a95b90364fba84bf7d22 (diff) | |
download | rails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.tar.gz rails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.tar.bz2 rails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.zip |
run railties tests in parallel, default to 2 cores
-rw-r--r-- | activesupport/lib/active_support/testing/isolation.rb | 39 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 2 |
2 files changed, 39 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index 1a0681e850..43cb16aefa 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -33,6 +33,45 @@ module ActiveSupport end module Isolation + require 'thread' + + class ParallelEach + include Enumerable + + # default to 2 cores + CORES = ENV['TEST_CORES'] || 2 + + def initialize list + @list = list + @queue = SizedQueue.new CORES + end + + def grep pattern + self.class.new super + end + + def each + threads = CORES.times.map { + Thread.new { + while job = @queue.pop + yield job + end + } + } + @list.each { |i| @queue << i } + CORES.times { @queue << nil } + threads.each(&:join) + end + end + + def self.included klass + klass.extend(Module.new { + def test_methods + ParallelEach.new super + end + }) + end + def self.forking_env? !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/)) end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 32deb143b0..800b1c90f0 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -23,8 +23,6 @@ require 'tmpdir' module TestHelpers module Paths - module_function - def app_template_path File.join Dir.tmpdir, 'app_template' end |