From d2dfdd9c01a21be17d50ecf3bfa1a6e9c88a66a3 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Sun, 12 Mar 2023 20:17:44 +0900 Subject: [PATCH] LogTest: Make sure to close LogDeviceIO Signed-off-by: Daijiro Fukuda --- test/test_log.rb | 80 +++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/test/test_log.rb b/test/test_log.rb index a344b532e3..29fd2a0ce9 100644 --- a/test/test_log.rb +++ b/test/test_log.rb @@ -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