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 <ashie@clear-code.com>
  • Loading branch information
ashie committed Jun 1, 2022
1 parent 944b16d commit 7224d90
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions test/plugin/test_in_tail.rb
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,13 @@ 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
super
# Restore default permission
system_config.instance_variable_set(:@file_permission, @default_permission)
end
Expand Down Expand Up @@ -1490,33 +1510,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 +1533,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 +1546,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 +1712,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 +1774,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 7224d90

Please sign in to comment.