fluentd 1.15.1 → 1.15.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,20 +5,35 @@ require_relative '../helper'
5
5
 
6
6
  require 'fileutils'
7
7
  require 'timeout'
8
+ require 'securerandom'
9
+ require 'fluent/file_wrapper'
8
10
 
9
11
  class TestFluentdCommand < ::Test::Unit::TestCase
10
- TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluentd#{ENV['TEST_ENV_NUMBER']}")
11
12
  SUPERVISOR_PID_PATTERN = /starting fluentd-[.0-9]+ pid=(\d+)/
12
13
  WORKER_PID_PATTERN = /starting fluentd worker pid=(\d+) /
13
14
 
15
+ def tmp_dir
16
+ File.join(File.dirname(__FILE__), "..", "tmp", "command" "fluentd#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10))
17
+ end
18
+
14
19
  setup do
15
- FileUtils.rm_rf(TMP_DIR)
16
- FileUtils.mkdir_p(TMP_DIR)
20
+ @tmp_dir = tmp_dir
21
+ FileUtils.mkdir_p(@tmp_dir)
17
22
  @supervisor_pid = nil
18
23
  @worker_pids = []
19
24
  ENV["TEST_RUBY_PATH"] = nil
20
25
  end
21
26
 
27
+ teardown do
28
+ begin
29
+ FileUtils.rm_rf(@tmp_dir)
30
+ rescue Errno::EACCES
31
+ # It may occur on Windows because of delete pending state due to delayed GC.
32
+ # Ruby 3.2 or later doesn't ignore Errno::EACCES:
33
+ # https://github.com/ruby/ruby/commit/983115cf3c8f75b1afbe3274f02c1529e1ce3a81
34
+ end
35
+ end
36
+
22
37
  def process_exist?(pid)
23
38
  begin
24
39
  r = Process.waitpid(pid, Process::WNOHANG)
@@ -30,17 +45,17 @@ class TestFluentdCommand < ::Test::Unit::TestCase
30
45
  end
31
46
 
32
47
  def create_conf_file(name, content, ext_enc = 'utf-8')
33
- conf_path = File.join(TMP_DIR, name)
34
- File.open(conf_path, "w:#{ext_enc}:utf-8") do |file|
48
+ conf_path = File.join(@tmp_dir, name)
49
+ Fluent::FileWrapper.open(conf_path, "w:#{ext_enc}:utf-8") do |file|
35
50
  file.write content
36
51
  end
37
52
  conf_path
38
53
  end
39
54
 
40
55
  def create_plugin_file(name, content)
41
- file_path = File.join(TMP_DIR, 'plugin', name)
56
+ file_path = File.join(@tmp_dir, 'plugin', name)
42
57
  FileUtils.mkdir_p(File.dirname(file_path))
43
- File.open(file_path, 'w') do |file|
58
+ Fluent::FileWrapper.open(file_path, 'w') do |file|
44
59
  file.write content
45
60
  end
46
61
  file_path
@@ -56,8 +71,8 @@ class TestFluentdCommand < ::Test::Unit::TestCase
56
71
  end
57
72
  end
58
73
 
59
- def execute_command(cmdline, chdir=TMP_DIR, env = {})
60
- null_stream = File.open(File::NULL, 'w')
74
+ def execute_command(cmdline, chdir=@tmp_dir, env = {})
75
+ null_stream = Fluent::FileWrapper.open(File::NULL, 'w')
61
76
  gemfile_path = File.expand_path(File.dirname(__FILE__) + "../../../Gemfile")
62
77
 
63
78
  env = { "BUNDLE_GEMFILE" => gemfile_path }.merge(env)
@@ -103,7 +118,7 @@ class TestFluentdCommand < ::Test::Unit::TestCase
103
118
  assert_error_msg = ""
104
119
  stdio_buf = ""
105
120
  begin
106
- execute_command(cmdline, TMP_DIR, env) do |pid, stdout|
121
+ execute_command(cmdline, @tmp_dir, env) do |pid, stdout|
107
122
  begin
108
123
  waiting(timeout) do
109
124
  while process_exist?(pid) && !matched
@@ -269,7 +284,7 @@ CONF
269
284
 
270
285
  sub_test_case 'with system configuration about root directory' do
271
286
  setup do
272
- @root_path = File.join(TMP_DIR, "rootpath")
287
+ @root_path = File.join(@tmp_dir, "rootpath")
273
288
  FileUtils.rm_rf(@root_path)
274
289
  @conf = <<CONF
275
290
  <system>
@@ -308,7 +323,7 @@ CONF
308
323
  end
309
324
 
310
325
  test 'fails to launch fluentd if specified root path is invalid path for directory' do
311
- File.open(@root_path, 'w') do |_|
326
+ Fluent::FileWrapper.open(@root_path, 'w') do |_|
312
327
  # create file and close it
313
328
  end
314
329
  conf_path = create_conf_file('existing_root_dir.conf', @conf)
@@ -508,7 +523,7 @@ CONF
508
523
 
509
524
  assert_fluentd_fails_to_start(
510
525
  create_cmdline(conf_path, "-p", File.dirname(plugin_path)),
511
- "in_buggy.rb:5: syntax error, unexpected end-of-input, expecting"
526
+ "in_buggy.rb:5: syntax error, unexpected end-of-input"
512
527
  )
513
528
  end
514
529
  end
@@ -554,7 +569,7 @@ CONF
554
569
 
555
570
  sub_test_case 'configured to run 2 workers' do
556
571
  setup do
557
- @root_path = File.join(TMP_DIR, "rootpath")
572
+ @root_path = File.join(@tmp_dir, "rootpath")
558
573
  FileUtils.rm_rf(@root_path)
559
574
  FileUtils.mkdir_p(@root_path)
560
575
  end
@@ -961,10 +976,10 @@ CONF
961
976
  </match>
962
977
  CONF
963
978
  ruby_path = ServerEngine.ruby_bin_path
964
- tmp_ruby_path = File.join(TMP_DIR, "ruby with spaces")
979
+ tmp_ruby_path = File.join(@tmp_dir, "ruby with spaces")
965
980
  if Fluent.windows?
966
981
  tmp_ruby_path << ".bat"
967
- File.open(tmp_ruby_path, "w") do |file|
982
+ Fluent::FileWrapper.open(tmp_ruby_path, "w") do |file|
968
983
  file.write "#{ruby_path} %*"
969
984
  end
970
985
  else
@@ -84,6 +84,7 @@ module Fluent::Config
84
84
  assert_nil(sc.enable_input_metrics)
85
85
  assert_nil(sc.enable_size_metrics)
86
86
  assert_nil(sc.enable_msgpack_time_support)
87
+ assert(!sc.enable_jit)
87
88
  assert_equal(:text, sc.log.format)
88
89
  assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format)
89
90
  end
@@ -102,6 +103,7 @@ module Fluent::Config
102
103
  'enable_msgpack_time_support' => ['enable_msgpack_time_support', true],
103
104
  'enable_input_metrics' => ['enable_input_metrics', true],
104
105
  'enable_size_metrics' => ['enable_size_metrics', true],
106
+ 'enable_jit' => ['enable_jit', true],
105
107
  )
106
108
  test "accepts parameters" do |(k, v)|
107
109
  conf = parse_text(<<-EOS)