aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_pool_test.rb
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2015-05-14 02:29:59 +0200
committerthedarkone <thedarkone2@gmail.com>2015-05-14 02:29:59 +0200
commite92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b (patch)
tree57d868e732b8aebfd7b5688bacb09d51dd43b1c4 /activerecord/test/cases/connection_pool_test.rb
parenta3923e667ca2c78734665389be964aa8492cfe1c (diff)
downloadrails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.tar.gz
rails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.tar.bz2
rails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.zip
AR::ConPool - establish connections outside of critical section.
Diffstat (limited to 'activerecord/test/cases/connection_pool_test.rb')
-rw-r--r--activerecord/test/cases/connection_pool_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index f5928814a3..3e563cd7cf 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -356,6 +356,40 @@ module ActiveRecord
pool.checkin connection
end
+
+ def test_concurrent_connection_establishment
+ all_threads_in_new_connection = ActiveSupport::Concurrency::Latch.new(@pool.size)
+ all_go = ActiveSupport::Concurrency::Latch.new
+
+ @pool.singleton_class.class_eval do
+ define_method(:new_connection) do
+ all_threads_in_new_connection.release
+ all_go.await
+ super()
+ end
+ end
+
+ connecting_threads = []
+ @pool.size.times do
+ connecting_threads << Thread.new { @pool.checkout }
+ end
+
+ begin
+ Timeout.timeout(5) do
+ # the kernel of the whole test is here, everything else is just scaffolding,
+ # this latch will not be released unless conn. pool allows for concurrent
+ # connection creation
+ all_threads_in_new_connection.await
+ end
+ rescue Timeout::Error
+ flunk 'pool unable to establish connections concurrently or implementation has ' <<
+ 'changed, this test then needs to patch a different :new_connection method'
+ ensure
+ # clean up the threads
+ all_go.release
+ connecting_threads.map(&:join)
+ end
+ end
end
end
end