aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-01-18 15:27:08 +0000
committerJon Leighton <j@jonathanleighton.com>2013-01-18 15:28:20 +0000
commit227cfe50c60190428be3a0b4ed4521a283ee03cf (patch)
tree7a22bc0d1cc1dffa00d471b6d0b0cbb96a7bf8de /activesupport/lib
parent8aebe30ef4d3d169bfb0900f4f4b396b74c8d20a (diff)
downloadrails-227cfe50c60190428be3a0b4ed4521a283ee03cf.tar.gz
rails-227cfe50c60190428be3a0b4ed4521a283ee03cf.tar.bz2
rails-227cfe50c60190428be3a0b4ed4521a283ee03cf.zip
MiniTest already defines a ParallelEach class
This may or may not fix the intermittent railties failures we've been seeing on the CI with Ruby 2.0. We'll see.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb50
1 files changed, 27 insertions, 23 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index aa87598926..f7a92ce03b 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -43,32 +43,36 @@ module ActiveSupport
module Isolation
require 'thread'
- class ParallelEach
- include Enumerable
-
- # default to 2 cores
- CORES = (ENV['TEST_CORES'] || 2).to_i
-
- def initialize list
- @list = list
- @queue = SizedQueue.new CORES
- end
+ # Recent versions of MiniTest (such as the one shipped with Ruby 2.0) already define
+ # a ParallelEach class.
+ unless defined? ParallelEach
+ class ParallelEach
+ include Enumerable
+
+ # default to 2 cores
+ CORES = (ENV['TEST_CORES'] || 2).to_i
+
+ def initialize list
+ @list = list
+ @queue = SizedQueue.new CORES
+ end
- def grep pattern
- self.class.new super
- end
+ def grep pattern
+ self.class.new super
+ end
- def each
- threads = CORES.times.map {
- Thread.new {
- while job = @queue.pop
- yield job
- 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)
+ @list.each { |i| @queue << i }
+ CORES.times { @queue << nil }
+ threads.each(&:join)
+ end
end
end