Skip to content

Commit

Permalink
test: fix logger handling
Browse files Browse the repository at this point in the history
`capture_log` is an old function and the tests are unstable on Windows
and macOS.

https://github.com/fluent/fluentd/blob/6c649d189b5cf65ccfce58f6952a31b24c775e72/lib/fluent/test/helpers.rb#L110-L122

We should use `Driver::logs` instead.

Signed-off-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
daipom committed Apr 5, 2023
1 parent 5081e88 commit cc50763
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions test/plugin/test_filter_flowcounter_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_filter
msgs << {'message'=> 'b' * 100}
end
d = create_driver
filtered, out = filter(d, msgs)
filtered, logs = filter(d, msgs)
assert_equal msgs, filtered
assert { out.include?("count:20") }
assert { logs.any? { |log| log.include?("count:20") } }
end

private
Expand All @@ -37,10 +37,8 @@ def filter(d, msgs)
msgs.each {|msg|
d.feed(msg)
}
}
out = capture_log(d.instance.log) do
d.instance.flush_emit(0)
end
[d.filtered_records, out]
}
[d.filtered_records, d.logs]
end
end
12 changes: 6 additions & 6 deletions test/plugin/test_out_flowcounter_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_num
d1.feed({'message'=> 'b' * 100})
d1.feed({'message'=> 'c' * 100})
end
d1.instance.flush_emit(60)
end
out = capture_log(d1.instance.log) { d1.instance.flush_emit(60) }
assert { out.include?("count:30") }
assert { d1.logs.any? { |log| log.include?("count:30") } }
end

def test_byte
Expand All @@ -51,9 +51,9 @@ def test_byte
d1.feed({'message'=> 'b' * 100})
d1.feed({'message'=> 'c' * 100})
end
d1.instance.flush_emit(60)
end
out = capture_log(d1.instance.log) { d1.instance.flush_emit(60) }
assert { out =~ /count:\d+\tindicator:byte\tunit:second/ }
assert { d1.logs.any? { |log| log =~ /count:\d+\tindicator:byte\tunit:second/ } }
end

def test_comment
Expand All @@ -64,8 +64,8 @@ def test_comment
d1.feed({'message'=> 'b' * 100})
d1.feed({'message'=> 'c' * 100})
end
d1.instance.flush_emit(60)
end
out = capture_log(d1.instance.log) { d1.instance.flush_emit(60) }
assert { out.include?("comment:foobar") }
assert { d1.logs.any? { |log| log.include?("comment:foobar") } }
end
end

0 comments on commit cc50763

Please sign in to comment.