Skip to content

Commit

Permalink
LogTest: Make sure to close LogDeviceIO
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
daipom committed Mar 14, 2023
1 parent f17a748 commit 879eeec
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions test/test_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,44 +602,48 @@ def test_log_with_logdevio(expected)

def test_log_rotates_specified_size_with_logdevio
with_timezone('utc') do
rotate_age = 2
rotate_size = 100
path = "#{@tmp_dir}/log-dev-io-#{rotate_size}-#{rotate_age}"
path0 = path + '.0'
path1 = path + '.1'

logdev = Fluent::LogDeviceIO.new(path, shift_age: rotate_age, shift_size: rotate_size)
logger = ServerEngine::DaemonLogger.new(logdev)
log = Fluent::Log.new(logger)

msg = 'a' * 101
log.info msg
assert_match msg, File.read(path)
assert_true File.exist?(path)
assert_true !File.exist?(path0)
assert_true !File.exist?(path1)

# create log.0
msg2 = 'b' * 101
log.info msg2
c = File.read(path)
c0 = File.read(path0)
assert_match msg2, c
assert_match msg, c0
assert_true File.exist?(path)
assert_true File.exist?(path0)
assert_true !File.exist?(path1)

# rotate
msg3 = 'c' * 101
log.info msg3
c = File.read(path)
c0 = File.read(path0)
assert_match msg3, c
assert_match msg2, c0
assert_true File.exist?(path)
assert_true File.exist?(path0)
assert_true !File.exist?(path1)
begin
rotate_age = 2
rotate_size = 100
path = "#{@tmp_dir}/log-dev-io-#{rotate_size}-#{rotate_age}"
path0 = path + '.0'
path1 = path + '.1'

logdev = Fluent::LogDeviceIO.new(path, shift_age: rotate_age, shift_size: rotate_size)
logger = ServerEngine::DaemonLogger.new(logdev)
log = Fluent::Log.new(logger)

msg = 'a' * 101
log.info msg
assert_match msg, File.read(path)
assert_true File.exist?(path)
assert_true !File.exist?(path0)
assert_true !File.exist?(path1)

# create log.0
msg2 = 'b' * 101
log.info msg2
c = File.read(path)
c0 = File.read(path0)
assert_match msg2, c
assert_match msg, c0
assert_true File.exist?(path)
assert_true File.exist?(path0)
assert_true !File.exist?(path1)

# rotate
msg3 = 'c' * 101
log.info msg3
c = File.read(path)
c0 = File.read(path0)
assert_match msg3, c
assert_match msg2, c0
assert_true File.exist?(path)
assert_true File.exist?(path0)
assert_true !File.exist?(path1)
ensure
logdev&.close
end
end
end

Expand Down

0 comments on commit 879eeec

Please sign in to comment.