diff --git a/.gitignore b/.gitignore index cf7c4c0..0f26641 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,6 @@ rdoc pkg tags .rvmrc +hydra-runner.log ## PROJECT::SPECIFIC diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index f96cc08..52b1398 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -13,10 +13,13 @@ module Hydra #:nodoc: class Runner include Hydra::Messages::Runner traceable('RUNNER') + + DEFAULT_LOG_FILE = 'hydra-runner.log' + # Boot up a runner. It takes an IO object (generally a pipe from its # parent) to send it messages on which files to execute. def initialize(opts = {}) - redirect_output( opts.fetch( :runner_log_file ) { nil } ) + redirect_output( opts.fetch( :runner_log_file ) { DEFAULT_LOG_FILE } ) reg_trap_sighup @io = opts.fetch(:io) { raise "No IO Object" } @@ -38,7 +41,6 @@ module Hydra #:nodoc: def reg_trap_sighup trap :SIGHUP do - File.open("_log_output", 'a'){ |f| f << "SIGHUP trapped"} stop end @runner_began = true @@ -290,8 +292,11 @@ module Hydra #:nodoc: end def redirect_output file_name - file_name = '/dev/null' unless file_name and !file_name.empty? - $stderr = $stdout = File.open(file_name, 'a') + begin + $stderr = $stdout = File.open(file_name, 'a') + rescue + $stderr = $stdout = File.open(DEFAULT_LOG_FILE, 'a') + end end end end diff --git a/test/master_test.rb b/test/master_test.rb index 2225e24..9458ef6 100644 --- a/test/master_test.rb +++ b/test/master_test.rb @@ -322,31 +322,37 @@ class MasterTest < Test::Unit::TestCase assert_file_exists "#{remote_dir_path}/#{runner_log_file}" end - # should "NOT create a runner log file when passing a incorrect log file path, but it should run successfully" do - # @pid = Process.fork do - # Hydra::Master.new( - # :files => [test_file], - # :workers => [{ - # :type => :ssh, - # :connect => 'localhost', - # :directory => remote_dir_path, - # :runners => 1 - # }], - # :verbose => false, - # :runner_log_file => 'invalid-dir/runner.log' - # ) - # end - # Process.waitpid @pid + should "create the default runner log file when passing an incorrect log file path" do + default_log_file = "#{remote_dir_path}/#{Hydra::Runner::DEFAULT_LOG_FILE}" # hydra-runner.log" + FileUtils.rm_f(default_log_file) - # assert_file_exists target_file # ensure the test was successfully ran - # assert_file_exists runner_log_file - # end + @pid = Process.fork do + Hydra::Master.new( + :files => [test_file], + :workers => [{ + :type => :ssh, + :connect => 'localhost', + :directory => remote_dir_path, + :runners => 1 + }], + :verbose => false, + :runner_log_file => 'invalid-dir/#{runner_log_file}' + ) + end + Process.waitpid @pid + + assert_file_exists target_file # ensure the test was successfully ran + assert_file_exists default_log_file #default log file + assert !File.exists?( "#{remote_dir_path}/#{runner_log_file}" ) + + FileUtils.rm_f(default_log_file) + end end private def runner_log_file - "hydra_runner.log" + "my-hydra-runner.log" end def add_infinite_worker_begin_to master_listener