提交 d5c1a5b1 编写于 作者: G Guo Xiang Tan

Improve tests for ActiveRecord::ConnectionAdapters::ConnectionPool configurations.

上级 dc796a0d
......@@ -156,6 +156,43 @@ def test_reap_inactive
@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
......
......@@ -61,9 +61,9 @@ def test_pool_has_reaper
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册