Skip to content

Commit

Permalink
Merge pull request #4430 from fluent/v1.16-backport-4375
Browse files Browse the repository at this point in the history
Backport (v1.16):  Fix or suppress failed tests on Ruby 3.3 (#4375)
  • Loading branch information
ashie authored Mar 11, 2024
2 parents 3b93711 + 48c2b05 commit 00aec89
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
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

0 comments on commit 00aec89

Please sign in to comment.