Some fixes to the tests and removed some commented-out code

This commit is contained in:
Arturo Pie 2011-06-02 15:02:58 -04:00
parent 5bd2e5f323
commit d6ff3ea5d2
5 changed files with 32 additions and 41 deletions

View File

@ -173,8 +173,6 @@ module Hydra #:nodoc:
def boot_ssh_worker(worker) def boot_ssh_worker(worker)
sync = Sync.new(worker, @sync, @verbose) sync = Sync.new(worker, @sync, @verbose)
# @environment+=" bundle exec" #used for manually testing
runners = worker.fetch('runners') { raise "You must specify the number of runners" } runners = worker.fetch('runners') { raise "You must specify the number of runners" }
command = worker.fetch('command') { command = worker.fetch('command') {
"RAILS_ENV=#{@environment} ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Worker.new(:io => Hydra::Stdio.new, :runners => #{runners}, :verbose => #{@verbose}, :runner_listeners => \'#{@string_runner_event_listeners}\' );\"" "RAILS_ENV=#{@environment} ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Worker.new(:io => Hydra::Stdio.new, :runners => #{runners}, :verbose => #{@verbose}, :runner_listeners => \'#{@string_runner_event_listeners}\' );\""

View File

@ -130,7 +130,6 @@ module Hydra #:nodoc:
rescue IOError => ex rescue IOError => ex
trace "Worker lost Master" trace "Worker lost Master"
shutdown shutdown
#Thread.exit
end end
end end
end end

View File

@ -201,8 +201,7 @@ class MasterTest < Test::Unit::TestCase
end end
context "running a local worker" do context "running a local worker" do
setup do should "run runner_end on successful termination" do
capture_stderr do # redirect stderr
@pid = Process.fork do @pid = Process.fork do
Hydra::Master.new( Hydra::Master.new(
:files => [test_file] * 6, :files => [test_file] * 6,
@ -212,27 +211,37 @@ class MasterTest < Test::Unit::TestCase
:verbose => false :verbose => false
) )
end end
end
end
should "run runner_end on successful termination" do
Process.waitpid @pid Process.waitpid @pid
assert File.exists?( target_file ) assert_file_exists alternate_target_file
wait_for_file_for_a_while alternate_target_file, 2
assert File.exists? alternate_target_file
end end
should "run runner_end after interruption signal" do should "run runner_end after interruption signal" do
class << @master_listener
def worker_begin( worker )
super
sleep 1 while true #ensure the process doesn't finish before killing it
end
end
capture_stderr do # redirect stderr
@pid = Process.fork do
Hydra::Master.new(
:files => [test_file],
:autosort => false,
:listeners => [@master_listener],
:runner_listeners => [@runner_listener],
:verbose => false
)
end
end
wait_for_runner_to_begin wait_for_runner_to_begin
Process.kill 'SIGINT', @pid Process.kill 'SIGINT', @pid
Process.waitpid @pid Process.waitpid @pid
wait_for_file_for_a_while alternate_target_file, 2 assert_file_exists alternate_target_file
assert File.exists? alternate_target_file # runner_end should create this file
end end
end end
@ -242,7 +251,7 @@ class MasterTest < Test::Unit::TestCase
capture_stderr do # redirect stderr capture_stderr do # redirect stderr
@pid = Process.fork do @pid = Process.fork do
Hydra::Master.new( Hydra::Master.new(
:files => [test_file] * 6, :files => [test_file],
:autosort => false, :autosort => false,
:listeners => [@master_listener], :listeners => [@master_listener],
:runner_listeners => [@runner_listener], :runner_listeners => [@runner_listener],
@ -265,9 +274,7 @@ class MasterTest < Test::Unit::TestCase
should "run runner_end on successful termination" do should "run runner_end on successful termination" do
Process.waitpid @pid Process.waitpid @pid
wait_for_file_for_a_while alternate_target_file, 2 assert_file_exists alternate_target_file
assert File.exists? target_file
assert File.exists? alternate_target_file
end end
end end
end end
@ -277,8 +284,7 @@ class MasterTest < Test::Unit::TestCase
def wait_for_runner_to_begin def wait_for_runner_to_begin
FileUtils.rm_f(@worker_began_flag) FileUtils.rm_f(@worker_began_flag)
wait_for_file_for_a_while @worker_began_flag, 2 assert_file_exists @worker_began_flag
assert File.exists?( @worker_began_flag ), "The worker didn't begin!!"
end end
# with a protection to avoid erasing something important in lib # with a protection to avoid erasing something important in lib

View File

@ -137,17 +137,14 @@ class RunnerTest < Test::Unit::TestCase
Process.wait(@parent) 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" do
run_the_runner(@pipe, [HydraExtension::RunnerListener::RunnerEndTest.new] ) run_the_runner(@pipe, [HydraExtension::RunnerListener::RunnerEndTest.new] )
Process.wait(@parent) Process.wait(@parent)
wait_for_file_for_a_while alternate_target_file, 2 assert_file_exists alternate_target_file
# ensure runner_end was fired
assert File.exists?( alternate_target_file )
end end
end end
@ -171,17 +168,6 @@ class RunnerTest < Test::Unit::TestCase
end end
module RunnerTestHelper module RunnerTestHelper
#this method allow us to wait for a file for a maximum number of time, so the
#test can pass in slower machines. This helps to speed up the tests
def wait_for_file_for_a_while file, time_to_wait
time_begin = Time.now
until Time.now - time_begin >= time_to_wait or File.exists?( file ) do
sleep 0.01
end
end
def request_a_file_and_verify_completion(pipe, file) def request_a_file_and_verify_completion(pipe, file)
pipe.identify_as_parent pipe.identify_as_parent

View File

@ -80,12 +80,14 @@ class Test::Unit::TestCase
#this method allow us to wait for a file for a maximum number of time, so the #this method allow us to wait for a file for a maximum number of time, so the
#test can pass in slower machines. This helps to speed up the tests #test can pass in slower machines. This helps to speed up the tests
def wait_for_file_for_a_while file, time_to_wait def assert_file_exists file, time_to_wait = 2
time_begin = Time.now time_begin = Time.now
until Time.now - time_begin >= time_to_wait or File.exists?( file ) do until Time.now - time_begin >= time_to_wait or File.exists?( file ) do
sleep 0.01 sleep 0.01
end end
assert File.exists?( file )
end end
end end