aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJonathan Rochkind <jonathan@dnil.net>2012-09-21 12:35:11 -0400
committerJonathan Rochkind <jonathan@dnil.net>2012-09-24 16:20:22 -0400
commit39087068c2e3c85f6839ea51eab4480673138a2b (patch)
treef9b8a6120ff14d04115e6d31fa17d69035d9a9f1 /activerecord/test
parent7b545ff911a3f9bd3c9b179a2c6ac6b70bab3ee0 (diff)
downloadrails-39087068c2e3c85f6839ea51eab4480673138a2b.tar.gz
rails-39087068c2e3c85f6839ea51eab4480673138a2b.tar.bz2
rails-39087068c2e3c85f6839ea51eab4480673138a2b.zip
ConnectionPool accepts spec key 'checkout_timeout'
Backport of #6441 cb6f83935 . Old 'wait_timeout' is still supported, but conflicts with mysql2 using that spec key for different thing. 'checkout_timeout' can now be used taking precedence for ConnectionPool over 'wait_timeout'.
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