Skip to content

Commit

Permalink
Merge pull request #3745 from fluent/fix-test-warinings
Browse files Browse the repository at this point in the history
Fix warnings on runnings tests
  • Loading branch information
ashie committed May 16, 2022
2 parents 74a84c0 + f262672 commit e9a58c8
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/command/ctl.rb
Expand Up @@ -146,7 +146,7 @@ def call_windows_event(command, pid_or_svcname)
event = Win32::Event.open("#{prefix}#{suffix}")
event.set
event.close
rescue Errno::ENOENT => e
rescue Errno::ENOENT
puts "Error: Cannot find the fluentd process with the event name: \"#{prefix}\""
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/config/literal_parser.rb
Expand Up @@ -191,9 +191,9 @@ def eval_embedded_code(code)
EOM
begin
@eval_context.instance_eval(code)
rescue SetNil => e
rescue SetNil
nil
rescue SetDefault => e
rescue SetDefault
:default
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/file_wrapper.rb
Expand Up @@ -106,7 +106,7 @@ def initialize(path, mode='r', sharemode=FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_S
@mode = mode


access, creationdisposition, seektoend = case mode.delete('b')
access, creationdisposition, _seektoend = case mode.delete('b')
when "r" ; [FILE_GENERIC_READ , OPEN_EXISTING, false]
when "r+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, OPEN_ALWAYS , false]
when "w" ; [FILE_GENERIC_WRITE , CREATE_ALWAYS, false]
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/parser_syslog.rb
Expand Up @@ -484,7 +484,7 @@ def parse_rfc5424(text, &block)

time = begin
@time_parser_rfc5424.parse(time_str)
rescue Fluent::TimeParser::TimeParseError => e
rescue Fluent::TimeParser::TimeParseError
@time_parser_rfc5424_without_subseconds.parse(time_str)
end
record['time'] = time_str if @keep_time_key
Expand Down
1 change: 0 additions & 1 deletion test/command/test_ctl.rb
Expand Up @@ -7,7 +7,6 @@

class TestFluentdCtl < ::Test::Unit::TestCase
def assert_win32_event(event_name, command, pid_or_svcname)
command, event_suffix = data
event = Win32::Event.new(event_name)
ipc = Win32::Ipc.new(event.handle)
ret = Win32::Ipc::TIMEOUT
Expand Down
1 change: 0 additions & 1 deletion test/config/test_system_config.rb
Expand Up @@ -174,7 +174,6 @@ def parse_text(text)
</log>
</system>
EOS
s = FakeSupervisor.new
sc = Fluent::SystemConfig.new(conf)
assert_equal(3, sc.log.rotate_age)
end
Expand Down
2 changes: 1 addition & 1 deletion test/config/test_types.rb
Expand Up @@ -190,7 +190,7 @@ class TestConfigTypes < ::Test::Unit::TestCase
data("val" => [:val, 'val'],
"v" => [:v, 'v'],
"value" => [:value, 'value'])
test 'enum' do |(expected, val, list)|
test 'enum' do |(expected, val)|
assert_equal expected, Config::ENUM_TYPE.call(val, {list: [:val, :value, :v]})
end

Expand Down
2 changes: 2 additions & 0 deletions test/plugin/in_tail/test_io_handler.rb
Expand Up @@ -107,6 +107,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
end

r.on_notify
assert_equal text.bytesize, update_pos
assert_equal 8, returned_lines[0].size
end

Expand All @@ -133,6 +134,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
end

r.on_notify
assert_equal text.bytesize, update_pos
assert_equal 5, returned_lines[0].size
assert_equal 3, returned_lines[1].size
end
Expand Down
9 changes: 0 additions & 9 deletions test/plugin/in_tail/test_position_file.rb
Expand Up @@ -40,10 +40,6 @@ def follow_inodes_block

test '.load' do
write_data(@file, TEST_CONTENT)
paths = {
"valid_path" => Fluent::Plugin::TailInput::TargetInfo.new("valid_path", 1),
"inode23bit" => Fluent::Plugin::TailInput::TargetInfo.new("inode23bit", 2),
}
Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})

@file.seek(0)
Expand Down Expand Up @@ -146,11 +142,6 @@ def follow_inodes_block
sub_test_case '#load' do
test 'compact invalid and convert 32 bit inode value' do
write_data(@file, TEST_CONTENT)
invalid_path = "invalidpath100000000000000000000000000000000"
paths = TEST_CONTENT_PATHS.merge({
invalid_path => Fluent::Plugin::TailInput::TargetInfo.new(invalid_path, 0),
"unwatched" => Fluent::Plugin::TailInput::TargetInfo.new("unwatched", 0),
})
Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})

@file.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_in_syslog.rb
Expand Up @@ -497,7 +497,7 @@ def test_send_keepalive_packet_can_be_enabled

def test_send_keepalive_packet_can_not_be_enabled_for_udp
assert_raise(Fluent::ConfigError) do
d = create_driver(ipv4_config + %[
create_driver(ipv4_config + %[
send_keepalive_packet true
])
end
Expand Down
51 changes: 25 additions & 26 deletions test/plugin/test_in_tail.rb
Expand Up @@ -152,13 +152,13 @@ def create_driver(conf = SINGLE_LINE_CONFIG, use_common_conf = true)
sub_test_case "configure" do
test "plain single line" do
d = create_driver
assert_equal ["#{TMP_DIR}/tail.txt"], d.instance.paths
assert_equal "t1", d.instance.tag
assert_equal 2, d.instance.rotate_wait
assert_equal "#{TMP_DIR}/tail.pos", d.instance.pos_file
assert_equal 1000, d.instance.read_lines_limit
assert_equal -1, d.instance.read_bytes_limit_per_second
assert_equal false, d.instance.ignore_repeated_permission_error
assert_equal(["#{TMP_DIR}/tail.txt"], d.instance.paths)
assert_equal("t1", d.instance.tag)
assert_equal(2, d.instance.rotate_wait)
assert_equal("#{TMP_DIR}/tail.pos", d.instance.pos_file)
assert_equal(1000, d.instance.read_lines_limit)
assert_equal(-1, d.instance.read_bytes_limit_per_second)
assert_equal(false, d.instance.ignore_repeated_permission_error)
assert_nothing_raised do
d.instance.have_read_capability?
end
Expand All @@ -175,13 +175,13 @@ def create_driver(conf = SINGLE_LINE_CONFIG, use_common_conf = true)
test "multi paths with path_delimiter" do
c = config_element("ROOT", "", { "path" => "tail.txt|test2|tmp,dev", "tag" => "t1", "path_delimiter" => "|" })
d = create_driver(c + PARSE_SINGLE_LINE_CONFIG, false)
assert_equal ["tail.txt", "test2", "tmp,dev"], d.instance.paths
assert_equal(["tail.txt", "test2", "tmp,dev"], d.instance.paths)
end

test "multi paths with same path configured twice" do
c = config_element("ROOT", "", { "path" => "test1.txt,test2.txt,test1.txt", "tag" => "t1", "path_delimiter" => "," })
d = create_driver(c + PARSE_SINGLE_LINE_CONFIG, false)
assert_equal ["test2.txt","test1.txt"].sort, d.instance.paths.sort
assert_equal(["test2.txt","test1.txt"].sort, d.instance.paths.sort)
end

test "multi paths with invaid path_delimiter" do
Expand Down Expand Up @@ -223,7 +223,7 @@ def create_driver(conf = SINGLE_LINE_CONFIG, use_common_conf = true)
test "valid" do
conf = SINGLE_LINE_CONFIG + config_element("", "", { "encoding" => "utf-8" })
d = create_driver(conf)
assert_equal Encoding::UTF_8, d.instance.encoding
assert_equal(Encoding::UTF_8, d.instance.encoding)
end

test "invalid" do
Expand Down Expand Up @@ -1150,7 +1150,7 @@ def test_multiline_with_flush_interval(data)
config = data + config_element("", "", { "multiline_flush_interval" => "2s" })
d = create_driver(config)

assert_equal 2, d.instance.multiline_flush_interval
assert_equal(2, d.instance.multiline_flush_interval)

d.run(expect_emits: 1) do
File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
Expand Down Expand Up @@ -1375,13 +1375,13 @@ def test_expand_paths
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 }
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}"]) })
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 }
assert_equal(ex_paths - [ex_paths.last], plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

def test_expand_paths_with_duplicate_configuration
Expand All @@ -1392,7 +1392,7 @@ def test_expand_paths_with_duplicate_configuration
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
assert_equal expanded_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path }
assert_equal(expanded_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

def test_expand_paths_with_timezone
Expand All @@ -1414,8 +1414,8 @@ def test_expand_paths_with_timezone
# env : 2010-01-01 19:04:05 (UTC), tail path : 2010-01-02 03:04:05 (Asia/Taipei)
timeclass.should_receive(:now).with_no_args.and_return(Time.new(2010, 1, 1, 19, 4, 5))

assert_equal ex_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path }
assert_equal ex_paths - [ex_paths.first], exclude_plugin.expand_paths.values.sort_by { |path_ino| path_ino.path }
assert_equal(ex_paths, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
assert_equal(ex_paths - [ex_paths.first], exclude_plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end
end
end
Expand All @@ -1437,7 +1437,7 @@ def test_log_file_without_extension
})

plugin = create_driver(config, false).instance
assert_equal expected_files, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path }
assert_equal(expected_files, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end

def test_unwatched_files_should_be_removed
Expand All @@ -1459,7 +1459,7 @@ def test_unwatched_files_should_be_removed
waiting(20) { sleep 0.1 until Dir.glob("#{TMP_DIR}/*.txt").size == 0 } # Ensure file is deleted on Windows
waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size <= 0 }

assert_equal 0, d.instance.instance_variable_get(:@tails).keys.size
assert_equal(0, d.instance.instance_variable_get(:@tails).keys.size)

d.instance_shutdown
end
Expand Down Expand Up @@ -1511,8 +1511,8 @@ def capability_enabled?
"rotate_wait" => "2s"
}) + PARSE_SINGLE_LINE_CONFIG, false)

assert_equal readable_paths, d.instance.expand_paths.length
assert_equal result, d.instance.have_read_capability?
assert_equal(readable_paths, d.instance.expand_paths.length)
assert_equal(result, d.instance.have_read_capability?)
end
end

Expand All @@ -1530,7 +1530,7 @@ def test_pos_file_dir_creation
d = create_driver(config, false)
d.run
assert_path_exist("#{TMP_DIR}/pos")
assert_equal '755', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3]
assert_equal('755', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3])
ensure
cleanup_directory(TMP_DIR)
end
Expand All @@ -1554,9 +1554,9 @@ def test_pos_file_dir_creation_with_system_dir_permission

assert_path_exist("#{TMP_DIR}/pos")
if Fluent.windows?
assert_equal '755', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3]
assert_equal('755', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3])
else
assert_equal '744', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3]
assert_equal('744', File.stat("#{TMP_DIR}/pos").mode.to_s(8)[-3, 3])
end
ensure
cleanup_directory(TMP_DIR)
Expand Down Expand Up @@ -2246,7 +2246,7 @@ def test_limit_recently_modified

Timecop.freeze(now) do
plugin = create_driver(config, false).instance
assert_equal expected_files, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path }
assert_equal(expected_files, plugin.expand_paths.values.sort_by { |path_ino| path_ino.path })
end
end

Expand All @@ -2259,7 +2259,7 @@ def test_skip_refresh_on_startup
})
d = create_driver(config)
d.run(shutdown: false) {}
assert_equal 0, d.instance.instance_variable_get(:@tails).keys.size
assert_equal(0, d.instance.instance_variable_get(:@tails).keys.size)
# detect a file at first execution of in_tail_refresh_watchers timer
waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1 }
d.instance_shutdown
Expand Down Expand Up @@ -2333,7 +2333,6 @@ def test_EACCES
end

def test_shutdown_timeout
path = "#{TMP_DIR}/tail.txt"
File.open("#{TMP_DIR}/tail.txt", "wb") do |f|
(1024 * 1024 * 5).times do
f.puts "{\"test\":\"fizzbuzz\"}"
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_parser_syslog.rb
Expand Up @@ -644,7 +644,7 @@ def test_parser_type_method(engine)

data('regexp' => :regexp, 'string' => :string)
def test_parser_engine(engine)
d = @parser.configure({'parser_engine' => engine.to_s})
@parser.configure({'parser_engine' => engine.to_s})
assert_equal(engine, @parser.instance.parser_engine)
end
end
2 changes: 1 addition & 1 deletion test/plugin_helper/test_cert_option.rb
Expand Up @@ -19,7 +19,7 @@ class Dummy < Fluent::Plugin::TestBase
test 'raise an error for broken certificates_from_file file' do
d = Dummy.new
assert_raise Fluent::ConfigError do
certs = d.cert_option_certificates_from_file("test/plugin_helper/data/cert/empty.pem")
d.cert_option_certificates_from_file("test/plugin_helper/data/cert/empty.pem")
end
end
end

0 comments on commit e9a58c8

Please sign in to comment.