master can be configured via constructor. can set number runners on a local connection
This commit is contained in:
parent
b8cbe0feec
commit
969aedc2cc
8
TODO
8
TODO
|
@ -4,6 +4,14 @@ IO selection configuration for master
|
|||
|
||||
YML configuration
|
||||
|
||||
---
|
||||
hydra:
|
||||
workers:
|
||||
- type: local
|
||||
runners: 1
|
||||
- type: ssh
|
||||
connect: localhost
|
||||
|
||||
v0.6.0
|
||||
|
||||
multitest backwards compatible
|
||||
|
|
|
@ -18,7 +18,12 @@ module Hydra #:nodoc:
|
|||
@files = opts.fetch(:files) { [] }
|
||||
@workers = []
|
||||
@listeners = []
|
||||
boot_workers(opts.fetch(:workers) { [ {:runners => 1} ] } )
|
||||
# default is one worker that is configured to use a pipe with one runner
|
||||
worker_cfg = opts.fetch(:workers) {
|
||||
[ { :type => :local, :runners => 1} ]
|
||||
}
|
||||
|
||||
boot_workers worker_cfg
|
||||
process_messages
|
||||
end
|
||||
|
||||
|
@ -39,15 +44,26 @@ module Hydra #:nodoc:
|
|||
private
|
||||
|
||||
def boot_workers(workers)
|
||||
workers.each do |worker|
|
||||
pipe = Hydra::Pipe.new
|
||||
child = Process.fork do
|
||||
pipe.identify_as_child
|
||||
Hydra::Worker.new(:io => pipe, :runners => worker[:runners])
|
||||
end
|
||||
pipe.identify_as_parent
|
||||
@workers << { :pid => child, :io => pipe, :idle => false }
|
||||
workers.select{|worker| worker[:type] == :local}.each do |worker|
|
||||
boot_local_worker(worker)
|
||||
end
|
||||
workers.select{|worker| worker[:type] == :ssh}.each do |worker|
|
||||
boot_ssh_worker(worker)
|
||||
end
|
||||
end
|
||||
|
||||
def boot_local_worker(worker)
|
||||
pipe = Hydra::Pipe.new
|
||||
child = Process.fork do
|
||||
pipe.identify_as_child
|
||||
Hydra::Worker.new(:io => pipe, :runners => worker[:runners])
|
||||
end
|
||||
pipe.identify_as_parent
|
||||
@workers << { :pid => child, :io => pipe, :idle => false }
|
||||
end
|
||||
|
||||
def boot_ssh_worker(worker)
|
||||
raise "Don't know how to boot SSH workers yet"
|
||||
end
|
||||
|
||||
def process_messages
|
||||
|
|
|
@ -124,7 +124,7 @@ module Hydra #:nodoc:
|
|||
message.handle(self, r)
|
||||
end
|
||||
rescue IOError => ex
|
||||
$stderr.write "Worker lost Runner [#{r.inspect}]\n"
|
||||
$stderr.write "Worker lost Runner [#{r.inspect}]\n" if @verbose
|
||||
Thread.exit
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
|
||||
class WriteFileTest < Test::Unit::TestCase
|
||||
def test_slow
|
||||
sleep(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|||
|
||||
class WriteFileTest < Test::Unit::TestCase
|
||||
def test_write_a_file
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'w') do |f|
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,11 +11,40 @@ class MasterTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "run a test" do
|
||||
m = Hydra::Master.new({
|
||||
:files => Array(test_file)
|
||||
})
|
||||
Hydra::Master.new(
|
||||
:files => [test_file]
|
||||
)
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA", File.read(target_file)
|
||||
end
|
||||
|
||||
should "run a test 6 times on 1 worker with 2 runners" do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file]*6,
|
||||
:local => {
|
||||
:runners => 2
|
||||
}
|
||||
)
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA"*6, File.read(target_file)
|
||||
end
|
||||
|
||||
# The test being run sleeps for 2 seconds. So, if this was run in
|
||||
# series, it would take at least 20 seconds. This test ensures that
|
||||
# in runs in less than that amount of time. Since there are 10
|
||||
# runners to run the file 10 times, it should only take 2-4 seconds
|
||||
# based on overhead.
|
||||
should "run a slow test 10 times on 1 worker with 10 runners quickly" do
|
||||
start = Time.now
|
||||
Hydra::Master.new(
|
||||
:files => [File.join(File.dirname(__FILE__), 'fixtures', 'slow.rb')]*10,
|
||||
:workers => [
|
||||
{ :type => :local, :runners => 10 }
|
||||
]
|
||||
)
|
||||
finish = Time.now
|
||||
|
||||
assert (finish-start) < 15, "took #{finish-start} seconds"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue