提交 25f94971 编写于 作者: A Aaron Patterson

adding active_connections? to the connection pool for finding open connections

上级 4211866b
......@@ -352,6 +352,12 @@ def establish_connection(name, spec)
@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
end
# Returns true if there are any active connections among the connection
# pools that the ConnectionHandler is managing.
def active_connections?
connection_pools.values.any? { |pool| pool.active_connection? }
end
# Returns any connections in use by the current thread back to the pool,
# and also returns connections to the pool cached by threads that are no
# longer alive.
......
require "cases/helper"
module ActiveRecord
module ConnectionAdapters
class ConnectionHandlerTest < ActiveRecord::TestCase
def setup
@handler = ConnectionHandler.new
@handler.establish_connection 'america', Base.connection_pool.spec
@klass = Struct.new(:name).new('america')
end
def test_retrieve_connection
assert @handler.retrieve_connection(@klass)
end
def test_active_connections?
assert !@handler.active_connections?
assert @handler.retrieve_connection(@klass)
assert @handler.active_connections?
@handler.clear_active_connections!
assert !@handler.active_connections?
end
def test_retrieve_connection_pool_with_ar_base
assert_nil @handler.retrieve_connection_pool(ActiveRecord::Base)
end
def test_retrieve_connection_pool
assert_not_nil @handler.retrieve_connection_pool(@klass)
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册