1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Run in a separated process to run finalizers certainly

This commit is contained in:
Nobuyoshi Nakada 2021-07-27 14:55:20 +09:00 committed by GitHub
parent 2de7c29b37
commit cd49940cff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2021-07-27 14:55:52 +09:00
Merged: https://github.com/ruby/ruby/pull/4685

Merged-By: nobu <nobu@ruby-lang.org>

View file

@ -442,65 +442,43 @@ class TestGc < Test::Unit::TestCase
end end
def test_exception_in_finalizer_procs def test_exception_in_finalizer_procs
result = [] assert_in_out_err(["-W0"], "#{<<~"begin;"}\n#{<<~'end;'}", %w[c1 c2])
c1 = proc do c1 = proc do
result << :c1 puts "c1"
raise raise
end end
c2 = proc do c2 = proc do
result << :c2 puts "c2"
raise raise
end end
gen = proc do |depth| begin;
if depth > 0 tap do
gen[depth-1]
else
obj = Object.new obj = Object.new
ObjectSpace.define_finalizer(obj, c1) ObjectSpace.define_finalizer(obj, c1)
ObjectSpace.define_finalizer(obj, c2) ObjectSpace.define_finalizer(obj, c2)
obj = nil obj = nil
end end
end end;
gen[100]
EnvUtil.suppress_warning do
1000.times do
break if result.size >= 2
GC.start
end
end
skip "finalizers did not get run" if result.empty?
assert_equal([:c1, :c2], result)
end end
def test_exception_in_finalizer_method def test_exception_in_finalizer_method
@result = [] assert_in_out_err(["-W0"], "#{<<~"begin;"}\n#{<<~'end;'}", %w[c1 c2])
def self.c1(x) def self.c1(x)
@result << :c1 puts "c1"
raise raise
end end
def self.c2(x) def self.c2(x)
@result << :c2 puts "c2"
raise raise
end end
gen = proc do |depth| begin;
if depth > 0 tap do
gen[depth-1]
else
obj = Object.new obj = Object.new
ObjectSpace.define_finalizer(obj, method(:c1)) ObjectSpace.define_finalizer(obj, method(:c1))
ObjectSpace.define_finalizer(obj, method(:c2)) ObjectSpace.define_finalizer(obj, method(:c2))
obj = nil obj = nil
end end
end end;
gen[100]
EnvUtil.suppress_warning do
1000.times do
break if @result.size >= 2
GC.start
end
end
skip "finalizers did not get run" if @result.empty?
assert_equal([:c1, :c2], @result)
end end
def test_object_ids_never_repeat def test_object_ids_never_repeat