Added a default runner log, and a test
This commit is contained in:
parent
0d4a1238f9
commit
8a536781b2
1
.gitignore
vendored
1
.gitignore
vendored
@ -19,5 +19,6 @@ rdoc
|
||||
pkg
|
||||
tags
|
||||
.rvmrc
|
||||
hydra-runner.log
|
||||
|
||||
## PROJECT::SPECIFIC
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user