From 265f13495fb326bd2e6a5bc9cae7e297e42893d0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 19 Jun 2012 17:08:15 -0700 Subject: run railties tests in parallel, default to 2 cores --- .../lib/active_support/testing/isolation.rb | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3