aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorGuo Xiang Tan <tgx_world@hotmail.com>2018-08-19 23:09:32 +0800
committerGuo Xiang Tan <tgx_world@hotmail.com>2018-08-20 17:49:05 +0800
commitce048a7a73e340843b2e7ec96f8b383ba99f102b (patch)
treefb58d9e70495aa3c5469cb0e4f5f282740200b8f /activerecord
parentd5c1a5b1f5ae405c8b7c2a875e1cd471575df2d4 (diff)
downloadrails-ce048a7a73e340843b2e7ec96f8b383ba99f102b.tar.gz
rails-ce048a7a73e340843b2e7ec96f8b383ba99f102b.tar.bz2
rails-ce048a7a73e340843b2e7ec96f8b383ba99f102b.zip
Speed up slow ConnectionPool test case.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/connection_pool_test.rb30
1 files changed, 19 insertions, 11 deletions
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)