aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorGuo Xiang Tan <tgx_world@hotmail.com>2018-08-19 10:29:02 +0800
committerGuo Xiang Tan <tgx_world@hotmail.com>2018-08-19 23:07:04 +0800
commitd5c1a5b1f5ae405c8b7c2a875e1cd471575df2d4 (patch)
treeeba2b02ccacf70f31f165115809d6f7c941ea34c /activerecord
parentdc796a0d407dfaf84abd464fc1aa2966cddb51e0 (diff)
downloadrails-d5c1a5b1f5ae405c8b7c2a875e1cd471575df2d4.tar.gz
rails-d5c1a5b1f5ae405c8b7c2a875e1cd471575df2d4.tar.bz2
rails-d5c1a5b1f5ae405c8b7c2a875e1cd471575df2d4.zip
Improve tests for ActiveRecord::ConnectionAdapters::ConnectionPool configurations.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/connection_pool_test.rb37
-rw-r--r--activerecord/test/cases/reaper_test.rb4
2 files changed, 39 insertions, 2 deletions
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 9ac03629c3..bd87a2d5f0 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -156,6 +156,43 @@ module ActiveRecord
@pool.connections.each { |conn| conn.close if conn.in_use? }
end
+ def test_idle_timeout_configuration
+ @pool.disconnect!
+ spec = ActiveRecord::Base.connection_pool.spec
+ spec.config.merge!(idle_timeout: "0.02")
+ @pool = ConnectionPool.new(spec)
+ idle_conn = @pool.checkout
+ @pool.checkin(idle_conn)
+
+ def idle_conn.seconds_idle
+ @seconds_idle
+ end
+
+ idle_conn.instance_variable_set(:@seconds_idle, 0.01)
+ @pool.flush
+ assert_equal 1, @pool.connections.length
+
+ idle_conn.instance_variable_set(:@seconds_idle, 0.02)
+ @pool.flush
+ assert_equal 0, @pool.connections.length
+ end
+
+ def test_disable_flush
+ @pool.disconnect!
+ spec = ActiveRecord::Base.connection_pool.spec
+ spec.config.merge!(idle_timeout: -5)
+ @pool = ConnectionPool.new(spec)
+ idle_conn = @pool.checkout
+ @pool.checkin(idle_conn)
+
+ def idle_conn.seconds_idle
+ 1
+ end
+
+ @pool.flush
+ assert_equal 1, @pool.connections.length
+ end
+
def test_flush
idle_conn = @pool.checkout
recent_conn = @pool.checkout
diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb
index b034fe3e3b..b630f782bc 100644
--- a/activerecord/test/cases/reaper_test.rb
+++ b/activerecord/test/cases/reaper_test.rb
@@ -61,9 +61,9 @@ module ActiveRecord
def test_reaping_frequency_configuration
spec = ActiveRecord::Base.connection_pool.spec.dup
- spec.config[:reaping_frequency] = 100
+ spec.config[:reaping_frequency] = "10.01"
pool = ConnectionPool.new spec
- assert_equal 100, pool.reaper.frequency
+ assert_equal 10.01, pool.reaper.frequency
end
def test_connection_pool_starts_reaper