From 07cacadc30d1cdf85f61cf56a6e5006a58739ac2 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Fri, 5 Jan 2024 18:34:13 +0900 Subject: [PATCH 1/5] 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 a2c4b4640eea836730957c9946a39f946d613329 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Tue, 9 Jan 2024 21:09:00 +0900 Subject: [PATCH 2/5] 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 171e2fbee1..e9250c9a68 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 d7e5a0247c1a02c72dea62f875bca3b20e8f63de Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 11 Jan 2024 09:42:02 +0900 Subject: [PATCH 3/5] 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 e9250c9a68..af816ae525 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 2c2cdc0426eac5995eb7f3a34191c204cafd9f29 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 11 Jan 2024 09:46:11 +0900 Subject: [PATCH 4/5] CI: Add Ruby 3.3 Signed-off-by: Takuro Ashie --- .github/workflows/linux-test.yaml | 2 +- .github/workflows/macos-test.yaml | 2 +- .github/workflows/windows-test.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux-test.yaml b/.github/workflows/linux-test.yaml index de2757a508..745ce9b1ca 100644 --- a/.github/workflows/linux-test.yaml +++ b/.github/workflows/linux-test.yaml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ['3.2', '3.1', '3.0', '2.7'] + ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7'] os: [ubuntu-latest] experimental: [false] include: diff --git a/.github/workflows/macos-test.yaml b/.github/workflows/macos-test.yaml index de54469ddd..9f45724fcc 100644 --- a/.github/workflows/macos-test.yaml +++ b/.github/workflows/macos-test.yaml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ['3.2', '3.1', '3.0', '2.7'] + ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7'] os: [macos-latest] experimental: [true] include: diff --git a/.github/workflows/windows-test.yaml b/.github/workflows/windows-test.yaml index 10792577b5..a1941be392 100644 --- a/.github/workflows/windows-test.yaml +++ b/.github/workflows/windows-test.yaml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ['3.2', '3.1', '2.7'] + ruby-version: ['3.3', '3.2', '3.1', '2.7'] os: - windows-latest experimental: [false] From 49030d7ba1ebc6cfdb17e973b9604db3d13dfdd4 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Thu, 11 Jan 2024 10:40:13 +0900 Subject: [PATCH 5/5] 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