From fa4f46a085516d16428071cc65434c6ad4a40756 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 +- test/command/test_fluentd.rb | 203 ++++++++++++++++++----------------- 2 files changed, 111 insertions(+), 100 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://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/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/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 20ed4e80ec..579840116d 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,6 +89,7 @@ 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) lines = stdio_buf.split("\n") @@ -169,105 +180,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