Skip to content

Commit

Permalink
test_fluentd: Suppress Errno::EACCES error on Ruby 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Sep 1, 2022
1 parent c068a32 commit 0bc1db5
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

require 'fileutils'
require 'timeout'
require 'securerandom'
require 'fluent/file_wrapper'

class TestFluentdCommand < ::Test::Unit::TestCase
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluentd#{ENV['TEST_ENV_NUMBER']}")
SUPERVISOR_PID_PATTERN = /starting fluentd-[.0-9]+ pid=(\d+)/
WORKER_PID_PATTERN = /starting fluentd worker pid=(\d+) /

def tmp_dir
File.join(File.dirname(__FILE__), "..", "tmp", "command" "fluentd#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10))
end

setup do
FileUtils.rm_rf(TMP_DIR)
FileUtils.mkdir_p(TMP_DIR)
@tmp_dir
FileUtils.mkdir_p(@tmp_dir)
@supervisor_pid = nil
@worker_pids = []
ENV["TEST_RUBY_PATH"] = nil
end

teardown do
begin
FileUtils.rm_rf(@tmp_dir)
rescue Errno::EACCES
# It may occur on Windows because of delete pending state due to delayed GC.
# Ruby 3.2 or later doesn't ignore Errno::EACCES:
# https://github.com/ruby/ruby/commit/983115cf3c8f75b1afbe3274f02c1529e1ce3a81
end
end

def process_exist?(pid)
begin
r = Process.waitpid(pid, Process::WNOHANG)
Expand All @@ -31,15 +45,15 @@ def process_exist?(pid)
end

def create_conf_file(name, content, ext_enc = 'utf-8')
conf_path = File.join(TMP_DIR, name)
conf_path = File.join(@tmp_dir, name)
Fluent::FileWrapper.open(conf_path, "w:#{ext_enc}:utf-8") do |file|
file.write content
end
conf_path
end

def create_plugin_file(name, content)
file_path = File.join(TMP_DIR, 'plugin', name)
file_path = File.join(@tmp_dir, 'plugin', name)
FileUtils.mkdir_p(File.dirname(file_path))
Fluent::FileWrapper.open(file_path, 'w') do |file|
file.write content
Expand All @@ -57,7 +71,7 @@ def create_cmdline(conf_path, *fluentd_options)
end
end

def execute_command(cmdline, chdir=TMP_DIR, env = {})
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 Down Expand Up @@ -104,7 +118,7 @@ def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout:
assert_error_msg = ""
stdio_buf = ""
begin
execute_command(cmdline, TMP_DIR, env) do |pid, stdout|
execute_command(cmdline, @tmp_dir, env) do |pid, stdout|
begin
waiting(timeout) do
while process_exist?(pid) && !matched
Expand Down Expand Up @@ -270,7 +284,7 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)

sub_test_case 'with system configuration about root directory' do
setup do
@root_path = File.join(TMP_DIR, "rootpath")
@root_path = File.join(@tmp_dir, "rootpath")
FileUtils.rm_rf(@root_path)
@conf = <<CONF
<system>
Expand Down Expand Up @@ -555,7 +569,7 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)

sub_test_case 'configured to run 2 workers' do
setup do
@root_path = File.join(TMP_DIR, "rootpath")
@root_path = File.join(@tmp_dir, "rootpath")
FileUtils.rm_rf(@root_path)
FileUtils.mkdir_p(@root_path)
end
Expand Down Expand Up @@ -962,7 +976,7 @@ def multi_workers_ready?
</match>
CONF
ruby_path = ServerEngine.ruby_bin_path
tmp_ruby_path = File.join(TMP_DIR, "ruby with spaces")
tmp_ruby_path = File.join(@tmp_dir, "ruby with spaces")
if Fluent.windows?
tmp_ruby_path << ".bat"
Fluent::FileWrapper.open(tmp_ruby_path, "w") do |file|
Expand Down

0 comments on commit 0bc1db5

Please sign in to comment.