Skip to content

Commit cd543a4

Browse files
committed
test_broken_bignum: use assert_separately instead of fork + waitpid2
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. Using assert_separately avoids this by spawning a subprocess via IO.popen instead of raw fork + waitpid2, and is also the idiomatic pattern for running test code in an isolated process within ruby/ruby's test framework.
1 parent bfd63d4 commit cd543a4

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

test/json/json_generator_test.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,24 +476,19 @@ def foo.to_h
476476
end
477477

478478
def test_broken_bignum # [ruby-core:38867]
479-
pid = fork do
479+
# Run in a separate process to avoid modifying core class of the parent
480+
# process and introducing race conditions when tests are run in parallel.
481+
assert_separately([], <<~RUBY)
482+
require 'json'
480483
x = 1 << 64
481484
x.class.class_eval do
482485
def to_s
483486
end
484487
end
485-
begin
488+
assert_raise(TypeError) do
486489
JSON::Ext::Generator::State.new.generate(x)
487-
exit 1
488-
rescue TypeError
489-
exit 0
490490
end
491-
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
491+
RUBY
497492
end
498493

499494
def test_hash_likeness_set_symbol

0 commit comments

Comments
 (0)