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

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.
This commit is contained in:
Jon Leighton 2013-01-18 15:27:08 +00:00
parent 8aebe30ef4
commit 227cfe50c6

View file

@ -43,32 +43,36 @@ module ActiveSupport
module Isolation
require 'thread'
class ParallelEach
include Enumerable
# 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
# default to 2 cores
CORES = (ENV['TEST_CORES'] || 2).to_i
def initialize list
@list = list
@queue = SizedQueue.new CORES
end
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