Created
March 29, 2012 06:28
-
-
Save takoyakikamen/2234141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/unit' | |
require 'drb' | |
require 'rinda/tuplespace' | |
module MiniTest | |
class ParallelRunner < MiniTest::Unit | |
URI = 'druby://127.0.0.1:12345' | |
def _run_suites suites, type | |
hash = Hash[suites.map { |s| [s.name, s] }] | |
queue = fork { | |
ts = Rinda::TupleSpace.new | |
DRb.start_service URI, ts | |
puts DRb.uri | |
DRb.thread.join | |
} | |
children = 3.times.map { | |
fork { # consumer | |
DRb.start_service | |
ts = DRbObject.new_with_uri URI | |
loop do | |
_, name, type = ts.take ['run', nil, nil] | |
result = _run_suite hash[name], type | |
ts.write ['finished', result] | |
end | |
} | |
} | |
children << queue | |
DRb.start_service | |
ts = DRbObject.new_with_uri URI | |
suites.each { |suite| ts.write ['run', suite.name, type] } | |
x = suites.map { ts.take(['finished', nil])[1] } | |
Process.kill('KILL', *children) | |
x | |
end | |
end | |
end | |
MiniTest::Unit.runner = MiniTest::ParallelRunner.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rinda_evalを知ってますか?