From 7f84eae9d9458822e52e1dd90453ae8198c2beeb Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Fri, 5 Jan 2024 18:34:13 +0900 Subject: [PATCH 1/4] test: Check Socket::ResolutionError instead of SocketError on Ruby 3.3 Signed-off-by: Takuro Ashie --- test/plugin/test_out_forward.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index 80557c5989..3a7f9a2e10 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -156,7 +156,14 @@ def try_write(chunk) normal_conf = config_element('match', '**', {}, [ config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'}) ]) - assert_raise SocketError do + + if Socket.const_defined?(:ResolutionError) # as of Ruby 3.3 + error_class = Socket::ResolutionError + else + error_class = SocketError + end + + assert_raise error_class do create_driver(normal_conf) end @@ -165,7 +172,7 @@ def try_write(chunk) ]) @d = d = create_driver(conf) expected_log = "failed to resolve node name when configured" - expected_detail = 'server="test" error_class=SocketError' + expected_detail = "server=\"test\" error_class=#{error_class.name}" logs = d.logs assert{ logs.any?{|log| log.include?(expected_log) && log.include?(expected_detail) } } end From 1a7ad12e156d5fc385ac43d13924d0cb289c113d Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Tue, 9 Jan 2024 21:09:00 +0900 Subject: [PATCH 2/4] test_child_process: Replace some UTF-8 byte sequences with named variables Make easy to understand what these tests do. Signed-off-by: Takuro Ashie --- test/plugin_helper/test_child_process.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/plugin_helper/test_child_process.rb b/test/plugin_helper/test_child_process.rb index 5d84a0fd06..e720cef8c7 100644 --- a/test/plugin_helper/test_child_process.rb +++ b/test/plugin_helper/test_child_process.rb @@ -529,7 +529,9 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - expected = "\xEF\xBF\xBD\xEF\xBF\xBD\x00\xEF\xBF\xBD\xEF\xBF\xBD".force_encoding("utf-8") + replacement = "\uFFFD" # U+FFFD (REPLACEMENT CHARACTER) + nul = "\x00" # U+0000 (NUL) + expected = replacement * 2 + nul + replacement * 2 assert_equal expected, str @d.stop; @d.shutdown; @d.close; @d.terminate end @@ -538,10 +540,11 @@ def configure(conf) test 'can scrub characters without exceptions and replace specified chars' do m = Mutex.new str = nil + replacement = "?" Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do ran = false args = ['-e', 'STDOUT.set_encoding("ascii-8bit"); STDOUT.write "\xFF\xFF\x00\xF0\xF0"'] - @d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: '?') do |io| + @d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: replacement) do |io| m.lock ran = true str = io.read @@ -550,7 +553,8 @@ def configure(conf) sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran m.lock assert_equal Encoding.find('utf-8'), str.encoding - expected = "??\x00??".force_encoding("utf-8") + nul = "\x00" # U+0000 (NUL) + expected = replacement * 2 + nul + replacement * 2 assert_equal expected, str @d.stop; @d.shutdown; @d.close; @d.terminate end From 9796fd35718e7127e0ab2e1098ac74239fcd2aae Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 11 Jan 2024 09:42:02 +0900 Subject: [PATCH 3/4] test_child_process: Mark scrubbing tests as pending Behaviour of `IO#set_encoding` has been changed as of Ruby 3.3. We don't yet determine how to solve this issue, it might be better to address in Ruby. Signed-off-by: Takuro Ashie --- test/plugin_helper/test_child_process.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/plugin_helper/test_child_process.rb b/test/plugin_helper/test_child_process.rb index e720cef8c7..b498b7a0eb 100644 --- a/test/plugin_helper/test_child_process.rb +++ b/test/plugin_helper/test_child_process.rb @@ -515,6 +515,9 @@ def configure(conf) end test 'can scrub characters without exceptions' do + if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0') + pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)" + end m = Mutex.new str = nil Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do @@ -538,6 +541,9 @@ def configure(conf) end test 'can scrub characters without exceptions and replace specified chars' do + if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0') + pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)" + end m = Mutex.new str = nil replacement = "?" From 48c2b056cd19b2ddbe2fecc26b481a001a340814 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 11 Jan 2024 10:40:13 +0900 Subject: [PATCH 4/4] test_fluentd: Fix failed tests on Ruby 3.3 Signed-off-by: Takuro Ashie --- test/command/test_fluentd.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index 87c9d28d96..c6bd88d857 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -941,7 +941,7 @@ def multi_workers_ready? '-external-encoding' => '--external-encoding=utf-8', '-internal-encoding' => '--internal-encoding=utf-8', ) - test "-E option is set to RUBYOPT" do |opt| + test "-E option is set to RUBYOPT" do |base_opt| conf = < @type dummy @@ -952,6 +952,7 @@ def multi_workers_ready? CONF conf_path = create_conf_file('rubyopt_test.conf', conf) + opt = base_opt.dup opt << " #{ENV['RUBYOPT']}" if ENV['RUBYOPT'] assert_log_matches( create_cmdline(conf_path), @@ -991,9 +992,14 @@ def multi_workers_ready? CONF conf_path = create_conf_file('rubyopt_invalid_test.conf', conf) + if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0') + expected_phrase = 'ruby: invalid switch in RUBYOPT' + else + expected_phrase = 'Invalid option is passed to RUBYOPT' + end assert_log_matches( create_cmdline(conf_path), - 'Invalid option is passed to RUBYOPT', + expected_phrase, env: { 'RUBYOPT' => 'a' }, ) end