Skip to content

Commit 00aec89

Browse files
authored
Merge pull request #4430 from fluent/v1.16-backport-4375
Backport (v1.16): Fix or suppress failed tests on Ruby 3.3 (#4375)
2 parents 3b93711 + 48c2b05 commit 00aec89

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

Diff for: test/command/test_fluentd.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def multi_workers_ready?
941941
'-external-encoding' => '--external-encoding=utf-8',
942942
'-internal-encoding' => '--internal-encoding=utf-8',
943943
)
944-
test "-E option is set to RUBYOPT" do |opt|
944+
test "-E option is set to RUBYOPT" do |base_opt|
945945
conf = <<CONF
946946
<source>
947947
@type dummy
@@ -952,6 +952,7 @@ def multi_workers_ready?
952952
</match>
953953
CONF
954954
conf_path = create_conf_file('rubyopt_test.conf', conf)
955+
opt = base_opt.dup
955956
opt << " #{ENV['RUBYOPT']}" if ENV['RUBYOPT']
956957
assert_log_matches(
957958
create_cmdline(conf_path),
@@ -991,9 +992,14 @@ def multi_workers_ready?
991992
</match>
992993
CONF
993994
conf_path = create_conf_file('rubyopt_invalid_test.conf', conf)
995+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
996+
expected_phrase = 'ruby: invalid switch in RUBYOPT'
997+
else
998+
expected_phrase = 'Invalid option is passed to RUBYOPT'
999+
end
9941000
assert_log_matches(
9951001
create_cmdline(conf_path),
996-
'Invalid option is passed to RUBYOPT',
1002+
expected_phrase,
9971003
env: { 'RUBYOPT' => 'a' },
9981004
)
9991005
end

Diff for: test/plugin/test_out_forward.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ def try_write(chunk)
156156
normal_conf = config_element('match', '**', {}, [
157157
config_element('server', '', {'name' => 'test', 'host' => 'unexisting.yaaaaaaaaaaaaaay.host.example.com'})
158158
])
159-
assert_raise SocketError do
159+
160+
if Socket.const_defined?(:ResolutionError) # as of Ruby 3.3
161+
error_class = Socket::ResolutionError
162+
else
163+
error_class = SocketError
164+
end
165+
166+
assert_raise error_class do
160167
create_driver(normal_conf)
161168
end
162169

@@ -165,7 +172,7 @@ def try_write(chunk)
165172
])
166173
@d = d = create_driver(conf)
167174
expected_log = "failed to resolve node name when configured"
168-
expected_detail = 'server="test" error_class=SocketError'
175+
expected_detail = "server=\"test\" error_class=#{error_class.name}"
169176
logs = d.logs
170177
assert{ logs.any?{|log| log.include?(expected_log) && log.include?(expected_detail) } }
171178
end

Diff for: test/plugin_helper/test_child_process.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ def configure(conf)
515515
end
516516

517517
test 'can scrub characters without exceptions' do
518+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
519+
pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)"
520+
end
518521
m = Mutex.new
519522
str = nil
520523
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
@@ -529,19 +532,25 @@ def configure(conf)
529532
sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
530533
m.lock
531534
assert_equal Encoding.find('utf-8'), str.encoding
532-
expected = "\xEF\xBF\xBD\xEF\xBF\xBD\x00\xEF\xBF\xBD\xEF\xBF\xBD".force_encoding("utf-8")
535+
replacement = "\uFFFD" # U+FFFD (REPLACEMENT CHARACTER)
536+
nul = "\x00" # U+0000 (NUL)
537+
expected = replacement * 2 + nul + replacement * 2
533538
assert_equal expected, str
534539
@d.stop; @d.shutdown; @d.close; @d.terminate
535540
end
536541
end
537542

538543
test 'can scrub characters without exceptions and replace specified chars' do
544+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('3.3.0')
545+
pend "Behaviour of IO#set_encoding is changed as of Ruby 3.3 (#4058)"
546+
end
539547
m = Mutex.new
540548
str = nil
549+
replacement = "?"
541550
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
542551
ran = false
543552
args = ['-e', 'STDOUT.set_encoding("ascii-8bit"); STDOUT.write "\xFF\xFF\x00\xF0\xF0"']
544-
@d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: '?') do |io|
553+
@d.child_process_execute(:t13b, "ruby", arguments: args, mode: [:read], scrub: true, replace_string: replacement) do |io|
545554
m.lock
546555
ran = true
547556
str = io.read
@@ -550,7 +559,8 @@ def configure(conf)
550559
sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
551560
m.lock
552561
assert_equal Encoding.find('utf-8'), str.encoding
553-
expected = "??\x00??".force_encoding("utf-8")
562+
nul = "\x00" # U+0000 (NUL)
563+
expected = replacement * 2 + nul + replacement * 2
554564
assert_equal expected, str
555565
@d.stop; @d.shutdown; @d.close; @d.terminate
556566
end

0 commit comments

Comments
 (0)