Skip to content

Commit

Permalink
use files instead of pipes to test finalizers
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckremes committed Mar 22, 2016
1 parent c12f503 commit 31d4300
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions spec/ruby/core/objectspace/define_finalizer_spec.rb
Expand Up @@ -32,30 +32,33 @@ def handler.call(obj) end
# see [ruby-core:24095]
with_feature :fork do
it "calls finalizer on process termination" do
rd, wr = IO.pipe
@fname = tmp("finalizer_test.txt")
@contents = "finalized"
if Kernel::fork then
wr.close
rd.read.should == "finalized"
rd.close
loop { break if File.exists?(@fname) }
IO.read(@fname).should == @contents
else
rd.close
handler = ObjectSpaceFixtures.scoped(wr)
handler = Proc.new do
File.open(@fname, "w") { |f| f.write(@contents) }
end
obj = "Test"
ObjectSpace.define_finalizer(obj, handler)
exit 0
end
end

it "calls finalizer at exit even if it is self-referencing" do
rd, wr = IO.pipe
@fname = tmp("finalizer_test.txt")
@contents = "finalized"
if Kernel::fork then
wr.close
rd.read.should == "finalized"
rd.close
loop { break if File.exists?(@fname) }
IO.read(@fname).should == @contents
else
rd.close
obj = "Test"
handler = Proc.new { wr.write "finalized"; wr.close }
handler = Proc.new do
obj
File.open(@fname, "w") { |f| f.write(@contents) }
end
ObjectSpace.define_finalizer(obj, handler)
exit 0
end
Expand Down

0 comments on commit 31d4300

Please sign in to comment.