Skip to content

Commit

Permalink
test_in_tail: Fix failed tests on GNU/Linux
Browse files Browse the repository at this point in the history
* TestWithSystem should call super at setup and teadown
* EX_* should be placed in just under TailInputTest

Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Jun 1, 2022
1 parent 944b16d commit d8336e5
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
class TailInputTest < Test::Unit::TestCase
include FlexMock::TestCase

def tmp_dir
File.join(File.dirname(__FILE__), "..", "tmp", "tail#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10))
end

def setup
@tmp_dir = File.join(File.dirname(__FILE__), "..", "tmp", "tail#{ENV['TEST_ENV_NUMBER']}", SecureRandom.hex(10))
Fluent::Test.setup
@tmp_dir = tmp_dir
cleanup_directory(@tmp_dir)
end

Expand Down Expand Up @@ -42,8 +46,6 @@ def create_target_info(path)
Fluent::Plugin::TailInput::TargetInfo.new(path, Fluent::FileWrapper.stat(path).ino)
end

TMP_DIR = File.dirname(__FILE__) + "/../tmp/tail#{ENV['TEST_ENV_NUMBER']}"

ROOT_CONFIG = config_element("ROOT", "", {
"tag" => "t1",
"rotate_wait" => "2s",
Expand Down Expand Up @@ -107,6 +109,22 @@ def common_follow_inode_config
})
])

EX_ROTATE_WAIT = 0
EX_FOLLOW_INODES = false

def ex_config
config_element("", "", {
"tag" => "tail",
"path" => "test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log",
"format" => "none",
"pos_file" => "#{@tmp_dir}/tail.pos",
"read_from_head" => true,
"refresh_interval" => 30,
"rotate_wait" => "#{EX_ROTATE_WAIT}s",
"follow_inodes" => "#{EX_FOLLOW_INODES}",
})
end

def tailing_group_pattern
"/#{@tmp_dir}\/(?<podname>[a-z0-9]([-a-z0-9]*[a-z0-9])?(\/[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace>[^_]+)_(?<container>.+)-(?<docker_id>[a-z0-9]{6})\.log$/"
end
Expand Down Expand Up @@ -834,11 +852,14 @@ class TestWithSystem < self

def setup
omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
super
# Store default permission
@default_permission = system_config.instance_variable_get(:@file_permission)
end

def teardown
return if Fluent.windows?
super
# Restore default permission
system_config.instance_variable_set(:@file_permission, @default_permission)
end
Expand Down Expand Up @@ -1490,33 +1511,20 @@ def test_multiline_without_firstline(data)
sub_test_case "path" do
# * path test
# TODO: Clean up tests
EX_ROTATE_WAIT = 0
EX_FOLLOW_INODES = false

EX_CONFIG = config_element("", "", {
"tag" => "tail",
"path" => "test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log",
"format" => "none",
"pos_file" => "#{@tmp_dir}/tail.pos",
"read_from_head" => true,
"refresh_interval" => 30,
"rotate_wait" => "#{EX_ROTATE_WAIT}s",
"follow_inodes" => "#{EX_FOLLOW_INODES}",
})
def test_expand_paths
ex_paths = [
create_target_info('test/plugin/data/2010/01/20100102-030405.log'),
create_target_info('test/plugin/data/log/foo/bar.log'),
create_target_info('test/plugin/data/log/test.log')
]
plugin = create_driver(EX_CONFIG, false).instance
plugin = create_driver(ex_config, false).instance
flexstub(Time) do |timeclass|
timeclass.should_receive(:now).with_no_args.and_return(Time.new(2010, 1, 2, 3, 4, 5))
assert_equal(ex_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

# Test exclusion
exclude_config = EX_CONFIG + config_element("", "", { "exclude_path" => %Q(["#{ex_paths.last.path}"]) })
exclude_config = ex_config + config_element("", "", { "exclude_path" => %Q(["#{ex_paths.last.path}"]) })
plugin = create_driver(exclude_config, false).instance
assert_equal(ex_paths - [ex_paths.last], plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end
Expand All @@ -1526,9 +1534,9 @@ def test_expand_paths_with_duplicate_configuration
create_target_info('test/plugin/data/log/foo/bar.log'),
create_target_info('test/plugin/data/log/test.log')
]
duplicate_config = EX_CONFIG.dup
duplicate_config = ex_config.dup
duplicate_config["path"]="test/plugin/data/log/**/*.log, test/plugin/data/log/**/*.log"
plugin = create_driver(EX_CONFIG, false).instance
plugin = create_driver(ex_config, false).instance
assert_equal(expanded_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

Expand All @@ -1539,7 +1547,7 @@ def test_expand_paths_with_timezone
create_target_info('test/plugin/data/log/test.log')
]
['Asia/Taipei', '+08'].each do |tz_type|
taipei_config = EX_CONFIG + config_element("", "", {"path_timezone" => tz_type})
taipei_config = ex_config + config_element("", "", {"path_timezone" => tz_type})
plugin = create_driver(taipei_config, false).instance

# Test exclude
Expand Down Expand Up @@ -1705,7 +1713,7 @@ def test_z_refresh_watchers
create_target_info('test/plugin/data/log/foo/bar.log'),
create_target_info('test/plugin/data/log/test.log'),
]
plugin = create_driver(EX_CONFIG, false).instance
plugin = create_driver(ex_config, false).instance
sio = StringIO.new
plugin.instance_eval do
@pf = Fluent::Plugin::TailInput::PositionFile.load(sio, EX_FOLLOW_INODES, {}, logger: $log)
Expand Down Expand Up @@ -1767,7 +1775,7 @@ def test_z_refresh_watchers
DummyWatcher = Struct.new("DummyWatcher", :tag)

def test_tag
d = create_driver(EX_CONFIG, false)
d = create_driver(ex_config, false)
d.run {}
plugin = d.instance
mock(plugin.router).emit_stream('tail', anything).once
Expand Down

0 comments on commit d8336e5

Please sign in to comment.