Skip to content

Commit e871d07

Browse files
k0kubunbyroot
authored andcommitted
test_broken_bignum: avoid fork and subprocess for robustness
The raw fork + Process.waitpid2 pattern causes a SEGV on i686-linux in ruby/ruby CI. The crash occurs in waitpid_blocking_no_SIGCHLD going through the 32-bit vdso, which is a Ruby VM / kernel interaction issue unrelated to the json gem itself. Replace the fork-based approach with an in-process test that temporarily patches Integer#to_s and restores it via ensure. This avoids the fork SEGV on i686, works under valgrind (assert_separately doesn't), and is guarded to only run on CRuby (not JRuby/TruffleRuby) where the C extension behavior being tested exists.
1 parent c76b244 commit e871d07

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

test/json/json_generator_test.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -493,25 +493,20 @@ def foo.to_h
493493
assert_equal '2', state.indent
494494
end
495495

496-
def test_broken_bignum # [ruby-core:38867]
497-
pid = fork do
498-
x = 1 << 64
499-
x.class.class_eval do
496+
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"
497+
def test_broken_bignum # [ruby-core:38867]
498+
bignum = 1 << 64
499+
original_to_s = bignum.class.instance_method(:to_s)
500+
bignum.class.class_eval do
500501
def to_s
501502
end
502503
end
503-
begin
504-
JSON::Ext::Generator::State.new.generate(x)
505-
exit 1
506-
rescue TypeError
507-
exit 0
504+
assert_raise(TypeError) do
505+
JSON::Ext::Generator::State.new.generate(bignum)
508506
end
507+
ensure
508+
bignum.class.define_method(:to_s, original_to_s) if original_to_s
509509
end
510-
_, status = Process.waitpid2(pid)
511-
assert status.success?
512-
rescue NotImplementedError
513-
# forking to avoid modifying core class of a parent process and
514-
# introducing race conditions of tests are run in parallel
515510
end
516511

517512
def test_hash_likeness_set_symbol

0 commit comments

Comments
 (0)