diff options
Diffstat (limited to 'test/test_pool.rb')
-rw-r--r-- | test/test_pool.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_pool.rb b/test/test_pool.rb index 9e631c5..dc40e85 100644 --- a/test/test_pool.rb +++ b/test/test_pool.rb @@ -19,6 +19,22 @@ class ResourceWithArgs end end +class PoolClient < MogileFS::Client + attr_reader :alive + + def initialize(*args) + @args = args + @alive = true + end + + def backend + self + end + + def shutdown + @alive = false + end +end class TestPool < Test::Unit::TestCase @@ -95,5 +111,15 @@ class TestPool < Test::Unit::TestCase assert_equal o1, o2, "Objects must be reused" end + def test_auto_shutdown + pool = MogileFS::Pool.new(PoolClient, 666) + tmp = [] + 6.times { tmp << pool.get } + tmp.each { |obj| pool.put(obj) } + alive = Hash.new { |h,k| h[k] = 0 } + tmp.each { |obj| alive[obj.alive] += 1 } + assert_equal 3, alive[true] + assert_equal 3, alive[false] + end end |