diff options
author | thedarkone <thedarkone2@gmail.com> | 2015-05-14 02:29:59 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2015-05-14 02:29:59 +0200 |
commit | e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b (patch) | |
tree | 57d868e732b8aebfd7b5688bacb09d51dd43b1c4 /activerecord/test/cases | |
parent | a3923e667ca2c78734665389be964aa8492cfe1c (diff) | |
download | rails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.tar.gz rails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.tar.bz2 rails-e92f5a99d6a6306d96b4c7dd8f96c2822f2f2c7b.zip |
AR::ConPool - establish connections outside of critical section.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/connection_adapters/adapter_leasing_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/activerecord/test/cases/connection_adapters/adapter_leasing_test.rb b/activerecord/test/cases/connection_adapters/adapter_leasing_test.rb index fd5f183ab0..580568c8ac 100644 --- a/activerecord/test/cases/connection_adapters/adapter_leasing_test.rb +++ b/activerecord/test/cases/connection_adapters/adapter_leasing_test.rb @@ -6,7 +6,7 @@ module ActiveRecord class Pool < ConnectionPool def insert_connection_for_test!(c) synchronize do - @connections << c + adopt_connection(c) @available.add c end end 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 |