Browse files

run railties tests in parallel, default to 2 cores

  • Loading branch information...
1 parent a7e715e commit 265f13495fb326bd2e6a5bc9cae7e297e42893d0 @tenderlove tenderlove committed Jun 19, 2012
Showing with 39 additions and 2 deletions.
  1. +39 −0 activesupport/lib/active_support/testing/isolation.rb
  2. +0 −2 railties/test/isolation/abstract_unit.rb
View
39 activesupport/lib/active_support/testing/isolation.rb
@@ -33,6 +33,45 @@ def method_missing(name, *args)
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
2 railties/test/isolation/abstract_unit.rb
@@ -23,8 +23,6 @@
module TestHelpers
module Paths
- module_function
-
def app_template_path
File.join Dir.tmpdir, 'app_template'
end

0 comments on commit 265f134

Please sign in to comment.