Skip to content

Commit ddc88db

Browse files
authored
test_console_adapter: fix test failures caused by console gem update (#5360)
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: The `console` gem changed its duration log format from ` 0.0s` to ` 0.00s` in version 1.35.0 (socketry/console@14cf37d). This caused assertion failures in `ConsoleAdapterTest` when running on newer Ruby versions (3.3+). This patch will fix following error ``` $ bundle exec ruby -I"test:lib" test/log/test_console_adapter.rb Loaded suite test/log/test_console_adapter Started F ========================================================================================================================================== Failure: test_args[debug](ConsoleAdapterTest) test/log/test_console_adapter.rb:59:in 'ConsoleAdapterTest#test_args' 56: fatal: :fatal) 57: def test_args(level) 58: @console_logger.send(level, "subject", 1, 2, 3) => 59: assert_equal([ 60: "#{@timestamp_str} [#{level}]: 0.0s: subject\n" + 61: " | 1\n" + 62: " | 2\n" + <["2023-01-01 15:32:41 +0000 [debug]: 0.0s: subject\n" + " | 1\n" + " | 2\n" + " | 3\n"]> expected but was <["2023-01-01 15:32:41 +0000 [debug]: 0.00s: subject\n" + " | 1\n" + " | 2\n" + " | 3\n"]> diff: ? ["2023-01-01 15:32:41 +0000 [debug]: 0.00s: subject\n" + " | 1\n" + " | 2\n" + " | 3\n"] ========================================================================================================================================== F ... ``` **Docs Changes**: **Release Note**: Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent f36b379 commit ddc88db

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

test/log/test_console_adapter.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ def setup
1313
@logger = ServerEngine::DaemonLogger.new(@logdev)
1414
@fluent_log = Fluent::Log.new(@logger)
1515
@console_logger = Fluent::Log::ConsoleAdapter.wrap(@fluent_log)
16+
17+
# The log format was modified in https://github.com/socketry/console/commit/14cf37da3f5d3a95ba2766a6dbd4dbce87a4588c
18+
@duration_str = if Gem::Version.new(Console::VERSION) >= Gem::Version.new("1.35.0")
19+
" 0.00s"
20+
else
21+
" 0.0s"
22+
end
1623
end
1724

1825
def teardown
@@ -45,7 +52,7 @@ def test_reflect_log_level(data)
4552
fatal: :fatal)
4653
def test_string_subject(level)
4754
@console_logger.send(level, "subject")
48-
assert_equal(["#{@timestamp_str} [#{level}]: 0.0s: subject\n"],
55+
assert_equal(["#{@timestamp_str} [#{level}]: #{@duration_str}: subject\n"],
4956
@logdev.logs)
5057
end
5158

@@ -57,7 +64,7 @@ def test_string_subject(level)
5764
def test_args(level)
5865
@console_logger.send(level, "subject", 1, 2, 3)
5966
assert_equal([
60-
"#{@timestamp_str} [#{level}]: 0.0s: subject\n" +
67+
"#{@timestamp_str} [#{level}]: #{@duration_str}: subject\n" +
6168
" | 1\n" +
6269
" | 2\n" +
6370
" | 3\n"
@@ -76,7 +83,7 @@ def test_options(level)
7683
args = JSON.parse(lines[1..].collect { |str| str.sub(/\s+\|/, "") }.join("\n"))
7784
assert_equal([
7885
1,
79-
"#{@timestamp_str} [#{level}]: 0.0s: subject",
86+
"#{@timestamp_str} [#{level}]: #{@duration_str}: subject",
8087
{ "kwarg1" => "opt1", "kwarg2" => "opt2" }
8188
],
8289
[
@@ -94,7 +101,7 @@ def test_options(level)
94101
def test_block(level)
95102
@console_logger.send(level, "subject") { "block message" }
96103
assert_equal([
97-
"#{@timestamp_str} [#{level}]: 0.0s: subject\n" +
104+
"#{@timestamp_str} [#{level}]: #{@duration_str}: subject\n" +
98105
" | block message\n"
99106
],
100107
@logdev.logs)
@@ -109,8 +116,8 @@ def test_multiple_entries(level)
109116
@console_logger.send(level, "subject1")
110117
@console_logger.send(level, "line2")
111118
assert_equal([
112-
"#{@timestamp_str} [#{level}]: 0.0s: subject1\n",
113-
"#{@timestamp_str} [#{level}]: 0.0s: line2\n"
119+
"#{@timestamp_str} [#{level}]: #{@duration_str}: subject1\n",
120+
"#{@timestamp_str} [#{level}]: #{@duration_str}: line2\n"
114121
],
115122
@logdev.logs)
116123
end

0 commit comments

Comments
 (0)