-
-
Notifications
You must be signed in to change notification settings - Fork 390
Open
Description
While attempting to write a spec for jruby/jruby#7267 I ran into various issues and questions...
- There are no specs testing that GC eventually finalizes objects. This is obviously difficult to predict, but it is behavior I believe we should be testing one way or another.
- I was testing that exceptions in one finalizer are not seen by the next finalizer, but could not figure out a way to eliminate the warning output from Ruby indicating that a finalizer raised an exception.
The spec I attempted is below, but only makes a best attempt at forcing GC-oriented finalization and still does not suppress the error output.
it "hides raised exceptions from one finalizer to the next" do
def scoped(result)
Proc.new { result << "ok" if $!.nil?; raise }
end
def test(result)
obj = "Test"
# finalizer order may vary so both handlers check $! and raise an error
ObjectSpace.define_finalizer(obj, scoped(result))
ObjectSpace.define_finalizer(obj, scoped(result))
end
result = []
begin
old_verbose, $VERBOSE = $VERBOSE, false
test(result)
ensure
$VERBOSE = old_verbose
end
100.times { GC.start; break if result.size == 2 }
result.should == ["ok", "ok"]
end
I don't want to leave the fix for jruby/jruby#7267 untested, but I'm unsure how we should move forward to improve the GC-triggered finalization specs.
rubyFeedback
Metadata
Metadata
Assignees
Labels
No labels