提交 227cfe50 编写于 作者: J Jon Leighton

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.
上级 8aebe30e
......@@ -43,32 +43,36 @@ def method_missing(name, *args)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册