1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

run railties tests in parallel, default to 2 cores

This commit is contained in:
Aaron Patterson 2012-06-19 17:08:15 -07:00
parent a7e715e102
commit 265f13495f
2 changed files with 39 additions and 2 deletions

View file

@ -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

View file

@ -23,8 +23,6 @@ require 'tmpdir'
module TestHelpers
module Paths
module_function
def app_template_path
File.join Dir.tmpdir, 'app_template'
end