diff --git a/lib/fluent/test/driver/base.rb b/lib/fluent/test/driver/base.rb index dfd56ac1a9..b53f863db4 100644 --- a/lib/fluent/test/driver/base.rb +++ b/lib/fluent/test/driver/base.rb @@ -173,7 +173,7 @@ def instance_shutdown(log: Logger.new($stdout)) if @socket_manager_server @socket_manager_server.close - if @socket_manager_server.is_a?(String) && File.exist?(@socket_manager_path) + if @socket_manager_path.is_a?(String) && File.exist?(@socket_manager_path) FileUtils.rm_f @socket_manager_path end end diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 461e19ef1b..5719055521 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -71,6 +71,15 @@ def create_cmdline(conf_path, *fluentd_options) end end + def process_kill(pid) + begin + Process.kill(:TERM, pid) rescue nil + Timeout.timeout(10){ sleep 0.1 while process_exist?(pid) } + rescue Timeout::Error + Process.kill(:KILL, pid) rescue nil + end + end + def execute_command(cmdline, chdir=@tmp_dir, env = {}) null_stream = Fluent::FileWrapper.open(File::NULL, 'w') gemfile_path = File.expand_path(File.dirname(__FILE__) + "../../../Gemfile") @@ -85,12 +94,12 @@ def execute_command(cmdline, chdir=@tmp_dir, env = {}) yield pid, io # p(here: "execute command", pid: pid, worker_pids: @worker_pids) ensure - Process.kill(:KILL, pid) rescue nil + process_kill(pid) if @supervisor_pid - Process.kill(:KILL, @supervisor_pid) rescue nil + process_kill(@supervisor_pid) end @worker_pids.each do |cpid| - Process.kill(:KILL, cpid) rescue nil + process_kill(cpid) 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) } diff --git a/test/plugin/test_in_tcp.rb b/test/plugin/test_in_tcp.rb index b85a919c94..46061cb32c 100755 --- a/test/plugin/test_in_tcp.rb +++ b/test/plugin/test_in_tcp.rb @@ -226,6 +226,8 @@ def create_tcp_socket(host, port, &block) assert_equal 1, d.instance.log.logs.count { |l| l =~ /anonymous client/ } assert_equal 0, d.events.size + ensure + d.instance_shutdown if d&.instance end end diff --git a/test/plugin/test_out_http.rb b/test/plugin/test_out_http.rb index e245f74524..b0e1a469a7 100644 --- a/test/plugin/test_out_http.rb +++ b/test/plugin/test_out_http.rb @@ -378,6 +378,7 @@ def test_basic_auth_with_invalid_auth password hello? ]) + d.instance.system_config_override(root_dir: TMP_DIR) # Backup files are generated in TMP_DIR. d.run(default_tag: 'test.http', shutdown: false) do test_events.each { |event| d.feed(event) diff --git a/test/plugin/test_output.rb b/test/plugin/test_output.rb index c25c7b1afb..a04b19d469 100644 --- a/test/plugin/test_output.rb +++ b/test/plugin/test_output.rb @@ -803,7 +803,10 @@ def waiting(seconds) end test 'output plugin will call #try_write for plugin supports delayed commit only to flush buffer chunks' do + tmp_dir = File.join(__dir__, '../tmp/test_output') + i = create_output(:delayed) + i.system_config_override(root_dir: tmp_dir) # Backup files are generated in `tmp_dir`. try_write_called = false i.register(:try_write){|chunk| try_write_called = true; commit_write(chunk.unique_id) } @@ -820,6 +823,8 @@ def waiting(seconds) assert try_write_called i.stop; i.before_shutdown; i.shutdown; i.after_shutdown; i.close; i.terminate + ensure + FileUtils.rm_rf(tmp_dir) end test '#prefer_delayed_commit (returns false) decides delayed commit is disabled if both are implemented' do @@ -849,7 +854,10 @@ def waiting(seconds) end test '#prefer_delayed_commit (returns true) decides delayed commit is enabled if both are implemented' do + tmp_dir = File.join(__dir__, '../tmp/test_output') + i = create_output(:full) + i.system_config_override(root_dir: tmp_dir) # Backup files are generated in `tmp_dir`. write_called = false try_write_called = false i.register(:write){ |chunk| write_called = true } @@ -872,6 +880,8 @@ def waiting(seconds) assert try_write_called i.stop; i.before_shutdown; i.shutdown; i.after_shutdown; i.close; i.terminate + ensure + FileUtils.rm_rf(tmp_dir) end test 'flush_interval is ignored when flush_mode is not interval' do diff --git a/test/plugin_helper/test_server.rb b/test/plugin_helper/test_server.rb index 3dc308474b..a08734ae46 100644 --- a/test/plugin_helper/test_server.rb +++ b/test/plugin_helper/test_server.rb @@ -37,7 +37,7 @@ class Dummy < Fluent::Plugin::TestBase (@d.terminated? || @d.terminate) rescue nil @socket_manager_server.close - if @socket_manager_server.is_a?(String) && File.exist?(@socket_manager_path) + if @socket_manager_path.is_a?(String) && File.exist?(@socket_manager_path) FileUtils.rm_f @socket_manager_path end end