Skip to content

Commit

Permalink
Test: Move tests in LoggerInitializerTest
Browse files Browse the repository at this point in the history
Removed `rotate`, `rotate to max age` tests since
`LogTest::test_log_rotates_specified_size_with_logdevio` already
exists.

Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Mar 12, 2023
1 parent 20f8079 commit 6884858
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 120 deletions.
23 changes: 23 additions & 0 deletions test/test_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'timecop'
require 'logger'
require 'securerandom'
require 'pathname'

class LogTest < Test::Unit::TestCase
def tmp_dir
Expand Down Expand Up @@ -641,6 +642,28 @@ def test_log_rotates_specified_size_with_logdevio
assert_true !File.exist?(path1)
end
end

def test_reopen
path = Pathname(@tmp_dir) + "fluent.log"

logdev = Fluent::LogDeviceIO.new(path.to_s)
logger = ServerEngine::DaemonLogger.new(logdev)
log = Fluent::Log.new(logger, path: path)

message = "This is test message."

log.info message
log.reopen!
log.info message

assert { path.read.lines.select{ |line| line.include?(message) }.size == 2 }
# Assert reopening the same file.
# Especially, on Windows, the filepath is fixed for each process with rotate,
# so we need to care about this.
assert { path.parent.entries.size == 3 } # [".", "..", "fluent.log"]
ensure
logdev&.close
end
end

class PluginLoggerTest < Test::Unit::TestCase
Expand Down
120 changes: 0 additions & 120 deletions test/test_logger_initializer.rb

This file was deleted.

77 changes: 77 additions & 0 deletions test/test_supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'fileutils'
require 'tempfile'
require 'securerandom'
require 'pathname'

if Fluent.windows?
require 'win32/event'
Expand Down Expand Up @@ -680,6 +681,82 @@ def test_log_level_affects
sv.configure
assert_equal Fluent::Log::LEVEL_ERROR, $log.level
end

data(supervisor: true)
data(worker: false)
def test_log_path(supervisor)
log_path = Pathname(@tmp_dir) + "fluentd.log"
config_path = Pathname(@tmp_dir) + "fluentd.conf"
write_config config_path.to_s, ""

s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
assert_rr do
mock.proxy(File).chmod(0o777, log_path.parent.to_s).never
s.__send__(:setup_global_logger, supervisor: supervisor)
end

assert { log_path.parent.exist? }
ensure
$log.out.close
end

data(supervisor: true)
data(worker: false)
def test_dir_permission(supervisor)
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?

log_path = Pathname(@tmp_dir) + "fluentd.log"
config_path = Pathname(@tmp_dir) + "fluentd.conf"
conf = <<~EOC
<system>
dir_permission 0o777
</system>
EOC
write_config config_path.to_s, conf

s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
assert_rr do
mock.proxy(File).chmod(0o777, log_path.parent.to_s).once
s.__send__(:setup_global_logger, supervisor: supervisor)
end

assert { log_path.parent.exist? }
assert { (File.stat(log_path.parent).mode & 0xFFF) == 0o777 }
ensure
$log.out.close
end

def test_files_for_each_process_with_rotate_on_windows
omit "Only for Windows." unless Fluent.windows?

log_path = Pathname(@tmp_dir) + "log" + "fluentd.log"
config_path = Pathname(@tmp_dir) + "fluentd.conf"
conf = <<~EOC
<system>
<log>
rotate_age 5
</log>
</system>
EOC
write_config config_path.to_s, conf

s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
s.__send__(:setup_global_logger, supervisor: true)
$log.out.close

s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
s.__send__(:setup_global_logger, supervisor: false)
$log.out.close

ENV["SERVERENGINE_WORKER_ID"] = "1"
s = Fluent::Supervisor.new(config_path: config_path.to_s, log_path: log_path.to_s)
s.__send__(:setup_global_logger, supervisor: false)
$log.out.close

assert { log_path.parent.entries.size == 5 } # [".", "..", "logfile.log", ...]
ensure
ENV.delete("SERVERENGINE_WORKER_ID")
end
end

def test_enable_shared_socket
Expand Down

0 comments on commit 6884858

Please sign in to comment.