Better testing for finalization
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 622
- Forks
- 402
- Avg merge
- 14h 51m
- Merged PRs (30d)
- 6
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed finalizer spec in this issue and review the behavior described in jruby/jruby#7267. Determine how the suite can exercise GC-triggered finalization and isolate warning output; done means coverage for eventual finalization and for exceptions in one finalizer not affecting the next.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100