2010-01-29 16:45:42 +00:00
|
|
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
|
|
|
|
|
|
class MasterTest < Test::Unit::TestCase
|
|
|
|
context "with a file to test and a destination to verify" do
|
|
|
|
setup do
|
2010-01-29 19:56:02 +00:00
|
|
|
FileUtils.rm_f(target_file)
|
2010-01-29 16:45:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
2010-01-29 19:56:02 +00:00
|
|
|
FileUtils.rm_f(target_file)
|
2010-01-29 16:45:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
should "run a test" do
|
2010-01-29 20:26:32 +00:00
|
|
|
Hydra::Master.new(
|
|
|
|
:files => [test_file]
|
|
|
|
)
|
2010-01-29 19:56:02 +00:00
|
|
|
assert File.exists?(target_file)
|
|
|
|
assert_equal "HYDRA", File.read(target_file)
|
2010-01-29 16:45:42 +00:00
|
|
|
end
|
2010-01-29 20:26:32 +00:00
|
|
|
|
|
|
|
should "run a test 6 times on 1 worker with 2 runners" do
|
|
|
|
Hydra::Master.new(
|
|
|
|
:files => [test_file]*6,
|
2010-02-04 15:33:21 +00:00
|
|
|
:workers => [ { :type => :local, :runners => 2 } ]
|
2010-01-29 20:26:32 +00:00
|
|
|
)
|
|
|
|
assert File.exists?(target_file)
|
|
|
|
assert_equal "HYDRA"*6, File.read(target_file)
|
|
|
|
end
|
|
|
|
|
2010-02-04 16:18:06 +00:00
|
|
|
# The test being run sleeps for 5 seconds. So, if this was run in
|
|
|
|
# series, it would take at least 50 seconds. This test ensures that
|
2010-01-29 20:26:32 +00:00
|
|
|
# in runs in less than that amount of time. Since there are 10
|
2010-02-04 16:18:06 +00:00
|
|
|
# runners to run the file 10 times, it should only take 5-10 seconds
|
2010-01-29 20:26:32 +00:00
|
|
|
# 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
|
2010-02-04 16:18:06 +00:00
|
|
|
assert (finish-start) < 30, "took #{finish-start} seconds"
|
2010-01-29 20:27:48 +00:00
|
|
|
end
|
2010-01-29 20:26:32 +00:00
|
|
|
|
2010-01-29 20:27:48 +00:00
|
|
|
should "run a slow test 10 times on 2 workers with 5 runners each quickly" do
|
|
|
|
start = Time.now
|
|
|
|
Hydra::Master.new(
|
|
|
|
:files => [File.join(File.dirname(__FILE__), 'fixtures', 'slow.rb')]*10,
|
|
|
|
:workers => [
|
|
|
|
{ :type => :local, :runners => 5 },
|
|
|
|
{ :type => :local, :runners => 5 }
|
|
|
|
]
|
|
|
|
)
|
|
|
|
finish = Time.now
|
2010-01-29 20:26:32 +00:00
|
|
|
assert (finish-start) < 15, "took #{finish-start} seconds"
|
|
|
|
end
|
2010-01-29 22:21:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
should "run a test via ssh" do
|
|
|
|
Hydra::Master.new(
|
|
|
|
:files => [test_file],
|
|
|
|
:workers => [{
|
|
|
|
:type => :ssh,
|
|
|
|
:connect => 'localhost',
|
2010-02-03 21:03:16 +00:00
|
|
|
:directory => File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')),
|
2010-01-29 22:21:48 +00:00
|
|
|
:runners => 1
|
2010-02-03 21:03:16 +00:00
|
|
|
}]
|
2010-01-29 22:21:48 +00:00
|
|
|
)
|
|
|
|
assert File.exists?(target_file)
|
|
|
|
assert_equal "HYDRA", File.read(target_file)
|
|
|
|
end
|
2010-02-04 15:33:21 +00:00
|
|
|
|
|
|
|
should "run a test with config from a yaml file" do
|
|
|
|
Hydra::Master.new(
|
|
|
|
:files => [test_file],
|
|
|
|
:config => File.join(File.dirname(__FILE__), 'fixtures', 'config.yml')
|
|
|
|
)
|
|
|
|
assert File.exists?(target_file)
|
|
|
|
assert_equal "HYDRA", File.read(target_file)
|
|
|
|
end
|
2010-01-29 16:45:42 +00:00
|
|
|
end
|
|
|
|
end
|