Better testing for finalization
还没有人认领这个 Issue。
评估
调研方向
从本 issue 中提出的 finalizer 规范开始,并审查 jruby/jruby#7267 中描述的行为。确定 suite 如何执行由 GC 触发的 finalization 并隔离警告输出;完成标准是覆盖最终发生的 finalization,以及一个 finalizer 中的异常不会影响下一个 finalizer 的情况。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Ruby
- 星标
- 622
- 派生
- 402
- 平均合并
- 14 小时 51 分钟
- 30 天内合并 PR
- 6
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/spec 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 38/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
TheOdinProject/curriculum#31417 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
glossarist/glossarist-ruby#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·