Fixed indentation in master_test and a runner test

This commit is contained in:
Arturo Pie 2011-06-02 14:18:54 -04:00
parent 692c8cf790
commit 5bd2e5f323
2 changed files with 59 additions and 59 deletions

View File

@ -99,31 +99,57 @@ class RunnerTest < Test::Unit::TestCase
end end
should "be able to run a runner over ssh" do should "be able to run a runner over ssh" do
send_file_to_ssh_runner_and_verify_completion ssh = Hydra::SSH.new(
'localhost',
File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')),
"ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Runner.new(:io => Hydra::Stdio.new, :verbose => true);\""
)
assert ssh.gets.is_a?(Hydra::Messages::Runner::RequestFile)
ssh.write(Hydra::Messages::Worker::RunFile.new(:file => test_file))
# grab its response. This makes us wait for it to finish
echo = ssh.gets # get the ssh echo
response = ssh.gets
assert_equal Hydra::Messages::Runner::Results, response.class
# tell it to shut down
ssh.write(Hydra::Messages::Worker::Shutdown.new)
ssh.close
# ensure it ran
assert File.exists?(target_file)
assert_equal "HYDRA", File.read(target_file)
end end
context "using runner events" do context "using runner events" do
should "fire runner_begin event" do context "on successful termination" do
pipe = Hydra::Pipe.new setup do
parent = Process.fork do @pipe = Hydra::Pipe.new
request_a_file_and_verify_completion(pipe, test_file) @parent = Process.fork do
request_a_file_and_verify_completion(@pipe, test_file)
end
end end
run_the_runner(pipe, [HydraExtension::RunnerListener::RunnerBeginTest.new] ) should "fire runner_begin event" do
Process.wait(parent) run_the_runner(@pipe, [HydraExtension::RunnerListener::RunnerBeginTest.new] )
Process.wait(@parent)
# ensure runner_begin was fired # ensure runner_begin was fired
assert File.exists?( alternate_target_file ) assert File.exists?( alternate_target_file )
end end
should "fire runner_end event after successful shutting down" do should "fire runner_end event after successful shutting down" do
send_file_to_ssh_runner_and_verify_completion ", :runner_listeners => [HydraExtension::RunnerListener::RunnerEndTest.new]" run_the_runner(@pipe, [HydraExtension::RunnerListener::RunnerEndTest.new] )
Process.wait(@parent)
wait_for_file_for_a_while alternate_target_file, 2 wait_for_file_for_a_while alternate_target_file, 2
# ensure runner_end was fired # ensure runner_end was fired
assert File.exists?( alternate_target_file ) assert File.exists?( alternate_target_file )
end end
end
should "fire runner_end event after losing communication with worker" do should "fire runner_end event after losing communication with worker" do
pipe = Hydra::Pipe.new pipe = Hydra::Pipe.new
@ -178,32 +204,6 @@ class RunnerTest < Test::Unit::TestCase
pipe.identify_as_child pipe.identify_as_child
Hydra::Runner.new( :io => pipe, :runner_listeners => listeners ) Hydra::Runner.new( :io => pipe, :runner_listeners => listeners )
end end
def send_file_to_ssh_runner_and_verify_completion opts = ""
ssh = Hydra::SSH.new(
'localhost',
remote_dir_path,
"ruby -e \"require 'rubygems'; require 'hydra'; require '../test/fixtures/runner_listeners' ; Hydra::Runner.new(:io => Hydra::Stdio.new, :verbose => true #{opts} );\""
)
assert ssh.gets.is_a?(Hydra::Messages::Runner::RequestFile)
ssh.write(Hydra::Messages::Worker::RunFile.new(:file => test_file))
# grab its response. This makes us wait for it to finish
echo = ssh.gets # get the ssh echo
response = ssh.gets
assert_equal Hydra::Messages::Runner::Results, response.class
# tell it to shut down
ssh.write(Hydra::Messages::Worker::Shutdown.new)
ssh.close
# ensure it ran
assert File.exists?(target_file)
assert_equal "HYDRA", File.read(target_file)
end
end end
include RunnerTestHelper include RunnerTestHelper
end end