Skip to content

Commit

Permalink
take care about tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Nov 8, 2016
1 parent a9f5300 commit 9d8b6e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/plugin_helper/child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def child_process_exist?(pid)
true
end

# on_exit_callback = ->(status){ ... }
# status is an instance of Process::Status
# On Windows, exitstatus=0 and termsig=nil even when child process was killed.
def child_process_execute(
title, command,
arguments: nil, subprocess_name: nil, interval: nil, immediate: false, parallel: false,
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_out_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def create_test_data
sub_test_case 'when executed process dies unexpectedly' do
setup do
@gen_config = ->(num){ <<EOC
command ruby -e 'ARGV.first.to_i == 0 ? open(ARGV[1]){|f| STDOUT.write f.read} : (sleep 1 ; exit ARGV.first.to_i)' #{num} >#{TMP_DIR}/fail_out
command ruby -e "ARGV.first.to_i == 0 ? open(ARGV[1]){|f| STDOUT.write f.read} : (sleep 1 ; exit ARGV.first.to_i)" #{num} >#{TMP_DIR}/fail_out
<inject>
tag_key tag
time_key time
Expand Down
17 changes: 12 additions & 5 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ def configure(conf)
end

test 'can return exit status with signal code for child process killed by signal using on_exit_callback' do
omit "SIGQUIT is unsupported on Windows" if Fluent.windows?

assert File.exist?(@temp_path)

block_exits = false
Expand All @@ -663,7 +665,8 @@ def configure(conf)
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
pid = nil
@d.child_process_execute(:st1, "ruby", arguments: args, mode: [:read], on_exit_callback: cb) do |readio|
Process.kill(:QUIT, @d.instance_eval{ child_process_id })
pid = @d.instance_eval{ child_process_id }
Process.kill(:QUIT, pid)
str = readio.read.chomp rescue nil # empty string before EOF
block_exits = true
end
Expand Down Expand Up @@ -754,8 +757,10 @@ def configure(conf)

assert callback_called
assert exit_status
assert_nil exit_status.exitstatus
assert_equal 9, exit_status.termsig # SIGKILL
unless Fluent.windows? # On Windows, exitstatus is always 0 and termsig is nil
assert_nil exit_status.exitstatus
assert_equal 9, exit_status.termsig # SIGKILL
end
assert File.exist?(@temp_path)
end

Expand All @@ -776,8 +781,10 @@ def configure(conf)

assert callback_called
assert exit_status
assert_nil exit_status.exitstatus
assert_equal 9, exit_status.termsig # SIGKILL
unless Fluent.windows? # On Windows, exitstatus is always 0 and termsig is nil
assert_nil exit_status.exitstatus
assert_equal 9, exit_status.termsig # SIGKILL
end
assert File.exist?(@temp_path)
end
end
Expand Down

0 comments on commit 9d8b6e7

Please sign in to comment.