1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Expose connections available in the connection pool.

This commit is contained in:
José Valim 2010-01-11 23:27:43 +01:00
parent d382e93d8f
commit cccb998800
3 changed files with 5 additions and 1 deletions

View file

@ -56,7 +56,7 @@ module ActiveRecord
# * +wait_timeout+: number of seconds to block and wait for a connection # * +wait_timeout+: number of seconds to block and wait for a connection
# before giving up and raising a timeout error (default 5 seconds). # before giving up and raising a timeout error (default 5 seconds).
class ConnectionPool class ConnectionPool
attr_reader :spec attr_reader :spec, :connections
# Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification
# object which describes database connection information (e.g. adapter, # object which describes database connection information (e.g. adapter,

View file

@ -579,6 +579,8 @@ module ActiveRecord
protected protected
def translate_exception(exception, message) def translate_exception(exception, message)
return super unless exception.respond_to?(:errno)
case exception.errno case exception.errno
when 1062 when 1062
RecordNotUnique.new(message, exception) RecordNotUnique.new(message, exception)

View file

@ -61,12 +61,14 @@ class PooledConnectionsTest < ActiveRecord::TestCase
checkout_checkin_connections 1, 2 checkout_checkin_connections 1, 2
assert_equal 2, @connection_count assert_equal 2, @connection_count
assert_equal 0, @timed_out assert_equal 0, @timed_out
assert_equal 1, ActiveRecord::Base.connection_pool.connections.size
end end
def test_pooled_connection_checkin_two def test_pooled_connection_checkin_two
checkout_checkin_connections 2, 3 checkout_checkin_connections 2, 3
assert_equal 3, @connection_count assert_equal 3, @connection_count
assert_equal 0, @timed_out assert_equal 0, @timed_out
assert_equal 1, ActiveRecord::Base.connection_pool.connections.size
end end
def test_pooled_connection_checkout_existing_first def test_pooled_connection_checkout_existing_first