diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 14:09:39 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 14:09:39 -0800 |
commit | 17ff88c4d425d7b55ff1a1225cb56f293e7dd7eb (patch) | |
tree | f0fbe92f3839351ef0b6e617bf43c0d198bd601c /activerecord | |
parent | bf9e6c7c9b231207deaf75e5b71290df77614dc8 (diff) | |
download | rails-17ff88c4d425d7b55ff1a1225cb56f293e7dd7eb.tar.gz rails-17ff88c4d425d7b55ff1a1225cb56f293e7dd7eb.tar.bz2 rails-17ff88c4d425d7b55ff1a1225cb56f293e7dd7eb.zip |
connections can be removed from the pool
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 19 |
2 files changed, 28 insertions, 1 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 51d2f40a3f..3f54a98380 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -59,7 +59,7 @@ module ActiveRecord class ConnectionPool include MonitorMixin - attr_accessor :automatic_reconnect + attr_accessor :automatic_reconnect, :timeout attr_reader :spec, :connections # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification @@ -217,6 +217,14 @@ module ActiveRecord end end + # Remove a connection from the connection pool. The connection will + # remain open and active but will no longer be managed by this pool. + def remove(conn) + synchronize do + @connections.delete conn + end + end + private def new_connection diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 5b5bbc6500..d4d0f6258d 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -4,6 +4,8 @@ module ActiveRecord module ConnectionAdapters class ConnectionPoolTest < ActiveRecord::TestCase def setup + super + # Keep a duplicate pool so we do not bother others @pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec @@ -18,6 +20,23 @@ module ActiveRecord end end + def teardown + super + @pool.connections.each(&:close) + end + + def test_remove_connection + conn = @pool.checkout + assert conn.in_use? + + length = @pool.connections.length + @pool.remove conn + assert conn.in_use? + assert_equal(length - 1, @pool.connections.length) + ensure + conn.close + end + def test_active_connection? assert !@pool.active_connection? assert @pool.connection |