提交 17ff88c4 编写于 作者: A Aaron Patterson

connections can be removed from the pool

上级 bf9e6c7c
......@@ -59,7 +59,7 @@ module ConnectionAdapters
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 @@ def checkin(conn)
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
......
......@@ -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 @@ def setup
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册