Skip to content

Instantly share code, notes, and snippets.

@takoyakikamen
Created March 29, 2012 06:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoyakikamen/2234141 to your computer and use it in GitHub Desktop.
Save takoyakikamen/2234141 to your computer and use it in GitHub Desktop.
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
@seki
Copy link

seki commented Mar 29, 2012

rinda_evalを知ってますか?

@takoyakikamen
Copy link
Author

知らないです。教えて下さい。 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment