Skip to content

Commit

Permalink
Merge pull request #4515 from fluent/test-fix-tempfile-closed-at-gc
Browse files Browse the repository at this point in the history
test: fix IOError about Tempfile closed when GC
  • Loading branch information
ashie authored Jun 7, 2024
2 parents 69ef3ca + 3b27984 commit 94185f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
27 changes: 13 additions & 14 deletions test/plugin/in_tail/test_io_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions test/plugin/in_tail/test_position_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94185f4

Please sign in to comment.