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
|
pkg
|
||||||
tags
|
tags
|
||||||
.rvmrc
|
.rvmrc
|
||||||
|
hydra-runner.log
|
||||||
|
|
||||||
## PROJECT::SPECIFIC
|
## PROJECT::SPECIFIC
|
||||||
|
@ -13,10 +13,13 @@ module Hydra #:nodoc:
|
|||||||
class Runner
|
class Runner
|
||||||
include Hydra::Messages::Runner
|
include Hydra::Messages::Runner
|
||||||
traceable('RUNNER')
|
traceable('RUNNER')
|
||||||
|
|
||||||
|
DEFAULT_LOG_FILE = 'hydra-runner.log'
|
||||||
|
|
||||||
# Boot up a runner. It takes an IO object (generally a pipe from its
|
# Boot up a runner. It takes an IO object (generally a pipe from its
|
||||||
# parent) to send it messages on which files to execute.
|
# parent) to send it messages on which files to execute.
|
||||||
def initialize(opts = {})
|
def initialize(opts = {})
|
||||||
redirect_output( opts.fetch( :runner_log_file ) { nil } )
|
redirect_output( opts.fetch( :runner_log_file ) { DEFAULT_LOG_FILE } )
|
||||||
reg_trap_sighup
|
reg_trap_sighup
|
||||||
|
|
||||||
@io = opts.fetch(:io) { raise "No IO Object" }
|
@io = opts.fetch(:io) { raise "No IO Object" }
|
||||||
@ -38,7 +41,6 @@ module Hydra #:nodoc:
|
|||||||
|
|
||||||
def reg_trap_sighup
|
def reg_trap_sighup
|
||||||
trap :SIGHUP do
|
trap :SIGHUP do
|
||||||
File.open("_log_output", 'a'){ |f| f << "SIGHUP trapped"}
|
|
||||||
stop
|
stop
|
||||||
end
|
end
|
||||||
@runner_began = true
|
@runner_began = true
|
||||||
@ -290,8 +292,11 @@ module Hydra #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def redirect_output file_name
|
def redirect_output file_name
|
||||||
file_name = '/dev/null' unless file_name and !file_name.empty?
|
begin
|
||||||
$stderr = $stdout = File.open(file_name, 'a')
|
$stderr = $stdout = File.open(file_name, 'a')
|
||||||
|
rescue
|
||||||
|
$stderr = $stdout = File.open(DEFAULT_LOG_FILE, 'a')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -322,31 +322,37 @@ class MasterTest < Test::Unit::TestCase
|
|||||||
assert_file_exists "#{remote_dir_path}/#{runner_log_file}"
|
assert_file_exists "#{remote_dir_path}/#{runner_log_file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# should "NOT create a runner log file when passing a incorrect log file path, but it should run successfully" do
|
should "create the default runner log file when passing an incorrect log file path" do
|
||||||
# @pid = Process.fork do
|
default_log_file = "#{remote_dir_path}/#{Hydra::Runner::DEFAULT_LOG_FILE}" # hydra-runner.log"
|
||||||
# Hydra::Master.new(
|
FileUtils.rm_f(default_log_file)
|
||||||
# :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
|
|
||||||
|
|
||||||
# assert_file_exists target_file # ensure the test was successfully ran
|
@pid = Process.fork do
|
||||||
# assert_file_exists runner_log_file
|
Hydra::Master.new(
|
||||||
# end
|
: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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def runner_log_file
|
def runner_log_file
|
||||||
"hydra_runner.log"
|
"my-hydra-runner.log"
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_infinite_worker_begin_to master_listener
|
def add_infinite_worker_begin_to master_listener
|
||||||
|
Loading…
Reference in New Issue
Block a user