Skip to content

Instantly share code, notes, and snippets.

@niamster
Last active August 29, 2015 14:17
Show Gist options
  • Save niamster/7bbc8a0fcde30f122327 to your computer and use it in GitHub Desktop.
Save niamster/7bbc8a0fcde30f122327 to your computer and use it in GitHub Desktop.
test for celluloid issue #463
#!/usr/bin/env ruby
require 'celluloid'
require 'weakref'
class Bar
attr_reader :bar
def initialize(bar)
@bar = bar
ObjectSpace.define_finalizer(self, self.class.finalize(bar))
end
def self.finalize(bar)
proc { puts "finilize #{bar}" unless bar == :loop }
end
end
class Test
include Celluloid
def initialize
ObjectSpace.define_finalizer(self, self.class.finalize)
end
def self.finalize
proc { puts 'finilize test' }
end
def foo(arg)
Bar.new :gogogo
end
end
puts 'Start'
act = Test.new
arg = Bar.new(:coucou)
weak = WeakRef.new arg
act.foo arg
# if you comment out next line the main loop(just below) won't ever
act.foo nil # need a ctx switch to ensure previous Celluloid:Call is unlinked
act.foo nil # yet another context switch as a cure for rbx
arg = nil
act.terminate
act = nil
puts 'Wait'
bars = []
loop do
GC.start
break unless weak.weakref_alive?
bars << Bar.new(:loop)
end
puts 'PASS' unless weak.weakref_alive?
sleep 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment