diff --git a/test/plugin/in_tail/test_io_handler.rb b/test/plugin/in_tail/test_io_handler.rb index 647c4a55a1..0def36b31c 100644 --- a/test/plugin/in_tail/test_io_handler.rb +++ b/test/plugin/in_tail/test_io_handler.rb @@ -5,20 +5,19 @@ require 'tempfile' class IntailIOHandlerTest < Test::Unit::TestCase - setup do - @file = Tempfile.new('intail_io_handler').binmode - opened_file_metrics = Fluent::Plugin::LocalMetrics.new - opened_file_metrics.configure(config_element('metrics', '', {})) - closed_file_metrics = Fluent::Plugin::LocalMetrics.new - closed_file_metrics.configure(config_element('metrics', '', {})) - rotated_file_metrics = Fluent::Plugin::LocalMetrics.new - rotated_file_metrics.configure(config_element('metrics', '', {})) - @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics) - end - - teardown do - @file.close rescue nil - @file.unlink rescue nil + def setup + Tempfile.create('intail_io_handler') do |file| + file.binmode + @file = file + opened_file_metrics = Fluent::Plugin::LocalMetrics.new + opened_file_metrics.configure(config_element('metrics', '', {})) + closed_file_metrics = Fluent::Plugin::LocalMetrics.new + closed_file_metrics.configure(config_element('metrics', '', {})) + rotated_file_metrics = Fluent::Plugin::LocalMetrics.new + rotated_file_metrics.configure(config_element('metrics', '', {})) + @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics) + yield + end end def create_target_info diff --git a/test/plugin/in_tail/test_position_file.rb b/test/plugin/in_tail/test_position_file.rb index af692fdee5..b1957f7353 100644 --- a/test/plugin/in_tail/test_position_file.rb +++ b/test/plugin/in_tail/test_position_file.rb @@ -6,13 +6,12 @@ require 'tempfile' class IntailPositionFileTest < Test::Unit::TestCase - setup do - @file = Tempfile.new('intail_position_file_test').binmode - end - - teardown do - @file.close rescue nil - @file.unlink rescue nil + def setup + Tempfile.create('intail_position_file_test') do |file| + file.binmode + @file = file + yield + end end UNWATCHED_STR = '%016x' % Fluent::Plugin::TailInput::PositionFile::UNWATCHED_POSITION