Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modify connection pool callbacks to be compatible w/ new style

Signed-off-by: Yehuda Katz <wycats@gmail.com>
  • Loading branch information...
commit 471a394215e01ffae03bbafa027a44f63e0658b8 1 parent b0f55dc
@nicksieger nicksieger authored wycats committed
View
14 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -211,9 +211,10 @@ def checkout
# calling +checkout+ on this pool.
def checkin(conn)
@connection_mutex.synchronize do
- conn.run_callbacks :checkin
- @checked_out.delete conn
- @queue.signal
+ conn.run_callbacks :checkin do
+ @checked_out.delete conn
+ @queue.signal
+ end
end
end
@@ -255,9 +256,10 @@ def checkout_existing_connection
end
def checkout_and_verify(c)
- c.verify!
- c.run_callbacks :checkout
- @checked_out << c
+ c.run_callbacks :checkout do
+ c.verify!
+ @checked_out << c
+ end
c
end
end
View
21 activerecord/test/cases/pooled_connections_test.rb
@@ -4,14 +4,14 @@
class PooledConnectionsTest < ActiveRecord::TestCase
def setup
- super
+ @per_test_teardown = []
@connection = ActiveRecord::Base.remove_connection
end
def teardown
ActiveRecord::Base.clear_all_connections!
ActiveRecord::Base.establish_connection(@connection)
- super
+ @per_test_teardown.each {|td| td.call }
end
def checkout_connections
@@ -113,6 +113,23 @@ def test_with_connection_nesting_safety
assert_equal 3, after_count - before_count
end
+ def test_connection_pool_callbacks
+ checked_out, checked_in = false, false
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
+ set_callback(:checkout, :after) { checked_out = true }
+ set_callback(:checkin, :before) { checked_in = true }
+ end
+ @per_test_teardown << proc do
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
+ reset_callbacks :checkout
+ reset_callbacks :checkin
+ end
+ end
+ checkout_checkin_connections 1, 1
+ assert checked_out
+ assert checked_in
+ end
+
private
def add_record(name)
Please sign in to comment.
Something went wrong with that request. Please try again.