Skip to content

Commit

Permalink
Merge pull request #4050 from abetomo/clean-up-after-unit-tests
Browse files Browse the repository at this point in the history
Clean up after unit tests
  • Loading branch information
ashie authored Feb 17, 2023
2 parents 34f2c55 + 1c04889 commit 07e3ad1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/test/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions test/plugin/test_in_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/plugin/test_out_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def test_basic_auth_with_invalid_auth
password hello?
</auth>
])
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)
Expand Down
10 changes: 10 additions & 0 deletions test/plugin/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/plugin_helper/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07e3ad1

Please sign in to comment.