Skip to content

Commit

Permalink
test_in_tail: Check emitted events of rotation tests by one `assert_e…
Browse files Browse the repository at this point in the history
…qual`

Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed May 31, 2022
1 parent 10c56f5 commit f6994e9
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -920,39 +920,26 @@ def test_emit_with_system
def test_rotate_file(data)
config = data
events = sub_test_rotate_file(config, expect_emits: 2)
assert_equal(4, events.length)
assert_equal({"message" => "test3"}, events[0][2])
assert_equal({"message" => "test4"}, events[1][2])
assert_equal({"message" => "test5"}, events[2][2])
assert_equal({"message" => "test6"}, events[3][2])
assert_equal(3.upto(6).collect { |i| {"message" => "test#{i}"} },
events.collect { |event| event[2] })
end

data(flat: CONFIG_READ_FROM_HEAD + SINGLE_LINE_CONFIG,
parse: CONFIG_READ_FROM_HEAD + PARSE_SINGLE_LINE_CONFIG)
def test_rotate_file_with_read_from_head(data)
config = data
events = sub_test_rotate_file(config, expect_records: 6)
assert_equal(6, events.length)
assert_equal({"message" => "test1"}, events[0][2])
assert_equal({"message" => "test2"}, events[1][2])
assert_equal({"message" => "test3"}, events[2][2])
assert_equal({"message" => "test4"}, events[3][2])
assert_equal({"message" => "test5"}, events[4][2])
assert_equal({"message" => "test6"}, events[5][2])
assert_equal(1.upto(6).collect { |i| {"message" => "test#{i}"} },
events.collect { |event| event[2] })
end

data(flat: CONFIG_OPEN_ON_EVERY_UPDATE + CONFIG_READ_FROM_HEAD + SINGLE_LINE_CONFIG,
parse: CONFIG_OPEN_ON_EVERY_UPDATE + CONFIG_READ_FROM_HEAD + PARSE_SINGLE_LINE_CONFIG)
def test_rotate_file_with_open_on_every_update(data)
config = data
events = sub_test_rotate_file(config, expect_records: 6)
assert_equal(6, events.length)
assert_equal({"message" => "test1"}, events[0][2])
assert_equal({"message" => "test2"}, events[1][2])
assert_equal({"message" => "test3"}, events[2][2])
assert_equal({"message" => "test4"}, events[3][2])
assert_equal({"message" => "test5"}, events[4][2])
assert_equal({"message" => "test6"}, events[5][2])
assert_equal(1.upto(6).collect { |i| {"message" => "test#{i}"} },
events.collect { |event| event[2] })
end

data(flat: SINGLE_LINE_CONFIG,
Expand All @@ -973,13 +960,8 @@ def test_rotate_file_with_write_old(data)
}
# This test sometimes fails and it shows a potential bug of in_tail
# https://github.com/fluent/fluentd/issues/1434
assert_equal(6, events.length)
assert_equal({"message" => "test3"}, events[0][2])
assert_equal({"message" => "test4"}, events[1][2])
assert_equal({"message" => "test7"}, events[2][2])
assert_equal({"message" => "test8"}, events[3][2])
assert_equal({"message" => "test5"}, events[4][2])
assert_equal({"message" => "test6"}, events[5][2])
assert_equal([3, 4, 7, 8, 5, 6].collect { |i| {"message" => "test#{i}"} },
events.collect { |event| event[2] })
end

data(flat: SINGLE_LINE_CONFIG,
Expand All @@ -991,11 +973,8 @@ def test_rotate_file_with_write_old_and_no_new_file(data)
rotated_file.puts "test8"
rotated_file.flush
}
assert_equal(4, events.length)
assert_equal({"message" => "test3"}, events[0][2])
assert_equal({"message" => "test4"}, events[1][2])
assert_equal({"message" => "test7"}, events[2][2])
assert_equal({"message" => "test8"}, events[3][2])
assert_equal([3, 4, 7, 8].collect { |i| {"message" => "test#{i}"} },
events.collect { |event| event[2] })
end

def sub_test_rotate_file(config = nil, expect_emits: nil, expect_records: nil, timeout: 5)
Expand Down

0 comments on commit f6994e9

Please sign in to comment.