Skip to content

Commit

Permalink
test: terminate with sigterm instead of sigkill
Browse files Browse the repository at this point in the history
With SIGTERM, the shutdown process runs.
`SERVERENGINE_SOCKETMANAGER_*` etc. will be removed in the shutdown process.

When it cannot be terminated by SIGTERM, it is terminated by SIGKILL.

Signed-off-by: abetomo <[email protected]>
  • Loading branch information
abetomo committed Feb 16, 2023
1 parent 233a5f9 commit 1c04889
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 1c04889

Please sign in to comment.