diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 15:39:39 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 15:39:39 -0800 |
commit | 405aeb5da4eea3b9defdea2ce0920725dcd75308 (patch) | |
tree | e9905c562ab6c1ef187d878c783f1b29872b679b | |
parent | 3af68df0807a321a5fb35070b47438e2e2950182 (diff) | |
download | rails-405aeb5da4eea3b9defdea2ce0920725dcd75308.tar.gz rails-405aeb5da4eea3b9defdea2ce0920725dcd75308.tar.bz2 rails-405aeb5da4eea3b9defdea2ce0920725dcd75308.zip |
connection pool starts the reaper
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/reaper_test.rb | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index f5c2c4f339..7667d9a17c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -107,6 +107,7 @@ module ActiveRecord @timeout = spec.config[:wait_timeout] || 5 @reaper = Reaper.new self, spec.config[:reaping_frequency] + @reaper.start # default max pool size to 5 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5 diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb index 2fa544962a..9149d45e7c 100644 --- a/activerecord/test/cases/reaper_test.rb +++ b/activerecord/test/cases/reaper_test.rb @@ -52,6 +52,22 @@ module ActiveRecord pool = ConnectionPool.new spec assert_equal 100, pool.reaper.frequency end + + def test_connection_pool_starts_reaper + spec = ActiveRecord::Base.connection_pool.spec.dup + spec.config[:reaping_frequency] = 0.0001 + + pool = ConnectionPool.new spec + pool.timeout = 0 + + conn = pool.checkout + count = pool.connections.length + + conn.extend(Module.new { def active?; false; end; }) + + sleep 0.0002 + assert_equal(count - 1, pool.connections.length) + end end end end |