aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-09-25 06:36:43 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-09-25 06:36:43 -0700
commit8800aae3128056b4c9fc4cbc1e116a6817052898 (patch)
tree2d274b9e8a2e4d258ddba85a3b47d7397898306c /activerecord/test
parent114e1802132c944263a44af5f81da6d43c78124b (diff)
parent39087068c2e3c85f6839ea51eab4480673138a2b (diff)
downloadrails-8800aae3128056b4c9fc4cbc1e116a6817052898.tar.gz
rails-8800aae3128056b4c9fc4cbc1e116a6817052898.tar.bz2
rails-8800aae3128056b4c9fc4cbc1e116a6817052898.zip
Merge pull request #7684 from jrochkind/connection_pool_timeout_key_backport
ConnectionPool accepts spec key 'checkout_timeout' (Backport)
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/connection_pool_test.rb22
-rw-r--r--activerecord/test/cases/pooled_connections_test.rb4
2 files changed, 24 insertions, 2 deletions
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 5cecfa90e7..98759544b6 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -151,6 +151,28 @@ module ActiveRecord
def test_pool_sets_connection_visitor
assert @pool.connection.visitor.is_a?(Arel::Visitors::ToSql)
end
+
+ def test_timeout_spec_keys
+ # 'wait_timeout' is supported for backwards compat,
+ # 'checkout_timeout' is preferred to avoid conflicting
+ # with mysql2 adapters key of name 'wait_timeout' but
+ # different meaning.
+ config = ActiveRecord::Base.connection_pool.spec.config.merge(:wait_timeout => nil, :connection_timeout => nil)
+ method = ActiveRecord::Base.connection_pool.spec.adapter_method
+
+ pool = ConnectionPool.new ActiveRecord::Base::ConnectionSpecification.new(config.merge(:wait_timeout => 1), method)
+ assert_equal 1, pool.instance_variable_get(:@timeout)
+ pool.disconnect!
+
+ pool = ConnectionPool.new ActiveRecord::Base::ConnectionSpecification.new(config.merge(:checkout_timeout => 1), method)
+ assert_equal 1, pool.instance_variable_get(:@timeout)
+ pool.disconnect!
+
+ pool = ConnectionPool.new ActiveRecord::Base::ConnectionSpecification.new(config.merge(:wait_timeout => 6000, :checkout_timeout => 1), method)
+ assert_equal 1, pool.instance_variable_get(:@timeout)
+ pool.disconnect!
+ end
+
end
end
end
diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb
index bc3dfb1078..e69243a537 100644
--- a/activerecord/test/cases/pooled_connections_test.rb
+++ b/activerecord/test/cases/pooled_connections_test.rb
@@ -17,7 +17,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
end
def checkout_connections
- ActiveRecord::Base.establish_connection(@connection.merge({:pool => 2, :wait_timeout => 0.3}))
+ ActiveRecord::Base.establish_connection(@connection.merge({:pool => 2, :checkout_timeout => 0.3}))
@connections = []
@timed_out = 0
@@ -42,7 +42,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
end
def checkout_checkin_connections(pool_size, threads)
- ActiveRecord::Base.establish_connection(@connection.merge({:pool => pool_size, :wait_timeout => 0.5}))
+ ActiveRecord::Base.establish_connection(@connection.merge({:pool => pool_size, :checkout_timeout => 0.5}))
@connection_count = 0
@timed_out = 0
threads.times do