aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-28 16:43:34 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-28 16:43:34 -0700
commit4211866b7a1d0abf0c9150fd61ea67a8043b831d (patch)
tree8de03d27c551c085f35b6297f51e97917fadf83b /activerecord
parentec0cacc2938cb7159ae6085fc653b2be906a748f (diff)
downloadrails-4211866b7a1d0abf0c9150fd61ea67a8043b831d.tar.gz
rails-4211866b7a1d0abf0c9150fd61ea67a8043b831d.tar.bz2
rails-4211866b7a1d0abf0c9150fd61ea67a8043b831d.zip
adding active_connection? to the connection pool
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb6
-rw-r--r--activerecord/test/cases/connection_pool_test.rb8
2 files changed, 14 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 4297c26413..61e44d09bf 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -151,6 +151,12 @@ module ActiveRecord
@reserved_connections[current_connection_id] ||= checkout
end
+ # Check to see if there is an active connection in this connection
+ # pool.
+ def active_connection?
+ @reserved_connections.key? current_connection_id
+ end
+
# Signal that the thread is finished with the current connection.
# #release_connection releases the connection-thread association
# and returns the connection to the pool.
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 7ac14fa8d6..f92f4e62c5 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -18,6 +18,14 @@ module ActiveRecord
end
end
+ def test_active_connection?
+ assert !@pool.active_connection?
+ assert @pool.connection
+ assert @pool.active_connection?
+ @pool.release_connection
+ assert !@pool.active_connection?
+ end
+
def test_pool_caches_columns
columns = @pool.columns['posts']
assert_equal columns, @pool.columns['posts']