Some fixes to the tests and removed some commented-out code
This commit is contained in:
parent
5bd2e5f323
commit
d6ff3ea5d2
@ -173,8 +173,6 @@ module Hydra #:nodoc:
|
||||
def boot_ssh_worker(worker)
|
||||
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" }
|
||||
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}\' );\""
|
||||
|
@ -130,7 +130,6 @@ module Hydra #:nodoc:
|
||||
rescue IOError => ex
|
||||
trace "Worker lost Master"
|
||||
shutdown
|
||||
#Thread.exit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -201,9 +201,8 @@ class MasterTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
context "running a local worker" do
|
||||
setup do
|
||||
capture_stderr do # redirect stderr
|
||||
@pid = Process.fork do
|
||||
should "run runner_end on successful termination" do
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:autosort => false,
|
||||
@ -212,27 +211,37 @@ class MasterTest < Test::Unit::TestCase
|
||||
:verbose => false
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "run runner_end on successful termination" do
|
||||
Process.waitpid @pid
|
||||
|
||||
assert File.exists?( target_file )
|
||||
|
||||
wait_for_file_for_a_while alternate_target_file, 2
|
||||
assert File.exists? alternate_target_file
|
||||
assert_file_exists alternate_target_file
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Process.kill 'SIGINT', @pid
|
||||
|
||||
Process.waitpid @pid
|
||||
|
||||
wait_for_file_for_a_while alternate_target_file, 2
|
||||
assert File.exists? alternate_target_file # runner_end should create this file
|
||||
assert_file_exists alternate_target_file
|
||||
end
|
||||
end
|
||||
|
||||
@ -242,7 +251,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
capture_stderr do # redirect stderr
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:files => [test_file],
|
||||
:autosort => false,
|
||||
:listeners => [@master_listener],
|
||||
:runner_listeners => [@runner_listener],
|
||||
@ -265,9 +274,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
should "run runner_end on successful termination" do
|
||||
Process.waitpid @pid
|
||||
|
||||
wait_for_file_for_a_while alternate_target_file, 2
|
||||
assert File.exists? target_file
|
||||
assert File.exists? alternate_target_file
|
||||
assert_file_exists alternate_target_file
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -277,8 +284,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
def wait_for_runner_to_begin
|
||||
FileUtils.rm_f(@worker_began_flag)
|
||||
|
||||
wait_for_file_for_a_while @worker_began_flag, 2
|
||||
assert File.exists?( @worker_began_flag ), "The worker didn't begin!!"
|
||||
assert_file_exists @worker_began_flag
|
||||
end
|
||||
|
||||
# with a protection to avoid erasing something important in lib
|
||||
|
@ -137,17 +137,14 @@ class RunnerTest < Test::Unit::TestCase
|
||||
Process.wait(@parent)
|
||||
|
||||
# ensure runner_begin was fired
|
||||
assert File.exists?( alternate_target_file )
|
||||
assert_file_exists alternate_target_file
|
||||
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] )
|
||||
Process.wait(@parent)
|
||||
|
||||
wait_for_file_for_a_while alternate_target_file, 2
|
||||
|
||||
# ensure runner_end was fired
|
||||
assert File.exists?( alternate_target_file )
|
||||
assert_file_exists alternate_target_file
|
||||
end
|
||||
end
|
||||
|
||||
@ -171,17 +168,6 @@ class RunnerTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
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)
|
||||
pipe.identify_as_parent
|
||||
|
||||
|
@ -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
|
||||
#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
|
||||
|
||||
until Time.now - time_begin >= time_to_wait or File.exists?( file ) do
|
||||
sleep 0.01
|
||||
end
|
||||
|
||||
assert File.exists?( file )
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user