ruby / ruby/spec

Better testing for finalization

Open
#935 2 comments 1 reaction 0 assignees View on GitHub

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...

  1. 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.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.