Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport (v1.16): Fix or suppress failed tests on Ruby 3.3 (#4375) #4430

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<CONF
<source>
@type dummy
Expand All @@ -952,6 +952,7 @@ def multi_workers_ready?
</match>
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),
Expand Down Expand Up @@ -991,9 +992,14 @@ def multi_workers_ready?
</match>
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
Expand Down
11 changes: 9 additions & 2 deletions test/plugin/test_out_forward.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -529,19 +532,25 @@ 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
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 = "?"
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
Expand All @@ -550,7 +559,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
Expand Down
Loading