aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-06-19 17:08:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-06-19 17:08:23 -0700
commit265f13495fb326bd2e6a5bc9cae7e297e42893d0 (patch)
treeca4c06a89e2bd9bbe097d9b09d2d07d1d7e25274 /activesupport
parenta7e715e102ae1e905e69a95b90364fba84bf7d22 (diff)
downloadrails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.tar.gz
rails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.tar.bz2
rails-265f13495fb326bd2e6a5bc9cae7e297e42893d0.zip
run railties tests in parallel, default to 2 cores
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb39
1 files changed, 39 insertions, 0 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