From c068a3257bba20b61a04ceb512893ce3aaf55fb8 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 1 Sep 2022 17:37:57 +0900 Subject: [PATCH] test_supervisor: Suppress Errno::EACCES error on Ruby 3.2 Signed-off-by: Takuro Ashie --- test/test_supervisor.rb | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb index 78588f1b69..5c8b16a924 100644 --- a/test/test_supervisor.rb +++ b/test/test_supervisor.rb @@ -9,6 +9,7 @@ require 'uri' require 'fileutils' require 'tempfile' +require 'securerandom' if Fluent.windows? require 'win32/event' @@ -23,12 +24,24 @@ def config end end - TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp/supervisor#{ENV['TEST_ENV_NUMBER']}") - TMP_ROOT_DIR = File.join(TMP_DIR, 'root') + def tmp_dir + File.join(File.dirname(__FILE__), "tmp", "supervisor#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10)) + end def setup - FileUtils.rm_rf(TMP_DIR) - FileUtils.mkdir_p(TMP_DIR) + @tmp_dir = tmp_dir + @tmp_root_dir = File.join(@tmp_dir, 'root') + FileUtils.mkdir_p(@tmp_dir) + end + + def teardown + 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 write_config(path, data) @@ -49,7 +62,7 @@ def test_system_config enable_get_dump true process_name "process_name" log_level info - root_dir #{TMP_ROOT_DIR} + root_dir #{@tmp_root_dir} format json time_format %Y @@ -77,7 +90,7 @@ def test_system_config assert_equal true, sys_conf.enable_get_dump assert_equal "process_name", sys_conf.process_name assert_equal 2, sys_conf.log_level - assert_equal TMP_ROOT_DIR, sys_conf.root_dir + assert_equal @tmp_root_dir, sys_conf.root_dir assert_equal :json, sys_conf.log.format assert_equal '%Y', sys_conf.log.time_format counter_server = sys_conf.counter_server @@ -117,7 +130,7 @@ def test_system_config enable_get_dump: true process_name: "process_name" log_level: info - root_dir: !fluent/s "#{TMP_ROOT_DIR}" + root_dir: !fluent/s "#{@tmp_root_dir}" log: format: json time_format: "%Y" @@ -145,7 +158,7 @@ def test_system_config true, "process_name", 2, - TMP_ROOT_DIR, + @tmp_root_dir, :json, '%Y', '127.0.0.1', @@ -450,7 +463,7 @@ def server.config end def test_load_config - tmp_dir = "#{TMP_DIR}/dir/test_load_config.conf" + tmp_dir = "#{@tmp_dir}/dir/test_load_config.conf" conf_info_str = %[ log_level info @@ -521,7 +534,7 @@ def test_load_config end def test_load_config_for_logger - tmp_dir = "#{TMP_DIR}/dir/test_load_config_log.conf" + tmp_dir = "#{@tmp_dir}/dir/test_load_config_log.conf" conf_info_str = %[ @@ -548,7 +561,7 @@ def test_load_config_for_logger end def test_load_config_for_daemonize - tmp_dir = "#{TMP_DIR}/dir/test_load_config.conf" + tmp_dir = "#{@tmp_dir}/dir/test_load_config.conf" conf_info_str = %[ log_level info @@ -645,7 +658,7 @@ def test_logger ) def test_logger_with_rotate_age_and_rotate_size(rotate_age) opts = Fluent::Supervisor.default_options.merge( - log_path: "#{TMP_DIR}/test", log_rotate_age: rotate_age, log_rotate_size: 10 + log_path: "#{@tmp_dir}/test", log_rotate_age: rotate_age, log_rotate_size: 10 ) sv = Fluent::Supervisor.new(opts) log = sv.instance_variable_get(:@log) @@ -675,7 +688,7 @@ def test_override_default_log_rotate file.puts(config) file.flush opts = Fluent::Supervisor.default_options.merge( - log_path: "#{TMP_DIR}/test.log", config_path: file.path + log_path: "#{@tmp_dir}/test.log", config_path: file.path ) sv = Fluent::Supervisor.new(opts) @@ -700,7 +713,7 @@ def test_override_default_log_rotate_with_yaml_config file.puts(config) file.flush opts = Fluent::Supervisor.default_options.merge( - log_path: "#{TMP_DIR}/test.log", config_path: file.path, config_file_type: :yaml, + log_path: "#{@tmp_dir}/test.log", config_path: file.path, config_file_type: :yaml, ) sv = Fluent::Supervisor.new(opts)