aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_pool_test.rb
diff options
context:
space:
mode:
authorHemant Kumar <hkumar@crri.co.in>2010-09-30 12:12:23 +0530
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-06 14:45:56 -0600
commit2a04110f266b6ccaf94aeeae224af578a9620fbd (patch)
treebb9c08186fddbe3af7063faff9e478d0098f0c6f /activerecord/test/cases/connection_pool_test.rb
parenta0552d653b00e2e5b77e086b155e89fa22e4d6ed (diff)
downloadrails-2a04110f266b6ccaf94aeeae224af578a9620fbd.tar.gz
rails-2a04110f266b6ccaf94aeeae224af578a9620fbd.tar.bz2
rails-2a04110f266b6ccaf94aeeae224af578a9620fbd.zip
fix ruby 1.9 deadlock problem, fixes #5736 add connection pool tests
Diffstat (limited to 'activerecord/test/cases/connection_pool_test.rb')
-rw-r--r--activerecord/test/cases/connection_pool_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 82b3c36ed2..f0ec5c751c 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -26,6 +26,35 @@ module ActiveRecord
"threads should have been removed")
assert_equal pool.checkins.length, threads.length
end
+
+ def test_checkout_behaviour
+ pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec
+ connection = pool.connection
+ assert_not_nil connection
+ threads = []
+ 4.times do |i|
+ threads << Thread.new(i) do |pool_count|
+ connection = pool.connection
+ assert_not_nil connection
+ end
+ end
+
+ threads.each {|t| t.join}
+
+ Thread.new do
+ threads.each do |t|
+ thread_ids = pool.instance_variable_get(:@reserved_connections).keys
+ assert thread_ids.include?(t.object_id)
+ end
+
+ pool.connection
+ threads.each do |t|
+ thread_ids = pool.instance_variable_get(:@reserved_connections).keys
+ assert !thread_ids.include?(t.object_id)
+ end
+ end.join()
+
+ end
end
end
end