From cc50763a4f40f37047e8624cd96a49c4ff0284bb Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 22 Feb 2023 16:04:03 +0900 Subject: [PATCH] test: fix logger handling `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 --- test/plugin/test_filter_flowcounter_simple.rb | 10 ++++------ test/plugin/test_out_flowcounter_simple.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/test/plugin/test_filter_flowcounter_simple.rb b/test/plugin/test_filter_flowcounter_simple.rb index a33961b..aa3ebc1 100644 --- a/test/plugin/test_filter_flowcounter_simple.rb +++ b/test/plugin/test_filter_flowcounter_simple.rb @@ -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 @@ -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 diff --git a/test/plugin/test_out_flowcounter_simple.rb b/test/plugin/test_out_flowcounter_simple.rb index 78ce5ea..2063073 100644 --- a/test/plugin/test_out_flowcounter_simple.rb +++ b/test/plugin/test_out_flowcounter_simple.rb @@ -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 @@ -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 @@ -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