From ce048a7a73e340843b2e7ec96f8b383ba99f102b Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Sun, 19 Aug 2018 23:09:32 +0800 Subject: Speed up slow ConnectionPool test case. --- activerecord/test/cases/connection_pool_test.rb | 30 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'activerecord') diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index bd87a2d5f0..6aecf5fa35 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -91,7 +91,9 @@ module ActiveRecord end def test_full_pool_exception + @pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout @pool.size.times { assert @pool.checkout } + assert_raises(ConnectionTimeoutError) do @pool.checkout end @@ -164,15 +166,19 @@ module ActiveRecord idle_conn = @pool.checkout @pool.checkin(idle_conn) - def idle_conn.seconds_idle - @seconds_idle - end + idle_conn.instance_variable_set( + :@idle_since, + Concurrent.monotonic_time - 0.01 + ) - 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) + idle_conn.instance_variable_set( + :@idle_since, + Concurrent.monotonic_time - 0.02 + ) + @pool.flush assert_equal 0, @pool.connections.length end @@ -185,9 +191,10 @@ module ActiveRecord idle_conn = @pool.checkout @pool.checkin(idle_conn) - def idle_conn.seconds_idle - 1 - end + idle_conn.instance_variable_set( + :@idle_since, + Concurrent.monotonic_time - 1 + ) @pool.flush assert_equal 1, @pool.connections.length @@ -203,9 +210,10 @@ module ActiveRecord assert_equal 3, @pool.connections.length - def idle_conn.seconds_idle - 1000 - end + idle_conn.instance_variable_set( + :@idle_since, + Concurrent.monotonic_time - 1000 + ) @pool.flush(30) -- cgit v1.2.3