Skip to content

Commit 03bbab2

Browse files
committed
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 bfd63d4 commit 03bbab2

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

test/json/json_generator_test.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,25 +475,20 @@ def foo.to_h
475475
assert_equal '2', state.indent
476476
end
477477

478-
def test_broken_bignum # [ruby-core:38867]
479-
pid = fork do
480-
x = 1 << 64
481-
x.class.class_eval do
478+
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"
479+
def test_broken_bignum # [ruby-core:38867]
480+
bignum = 1 << 64
481+
original_to_s = bignum.class.instance_method(:to_s)
482+
bignum.class.class_eval do
482483
def to_s
483484
end
484485
end
485-
begin
486-
JSON::Ext::Generator::State.new.generate(x)
487-
exit 1
488-
rescue TypeError
489-
exit 0
486+
assert_raise(TypeError) do
487+
JSON::Ext::Generator::State.new.generate(bignum)
490488
end
489+
ensure
490+
bignum.class.define_method(:to_s, original_to_s) if original_to_s
491491
end
492-
_, status = Process.waitpid2(pid)
493-
assert status.success?
494-
rescue NotImplementedError
495-
# forking to avoid modifying core class of a parent process and
496-
# introducing race conditions of tests are run in parallel
497492
end
498493

499494
def test_hash_likeness_set_symbol

0 commit comments

Comments
 (0)