@@ -12,7 +12,15 @@ def setup
12
12
@previous_isolation_level = ActiveSupport ::IsolatedExecutionState . isolation_level
13
13
14
14
# Keep a duplicate pool so we do not bother others
15
- @db_config = ActiveRecord ::Base . connection_pool . db_config
15
+ config = ActiveRecord ::Base . connection_pool . db_config
16
+ @db_config = ActiveRecord ::DatabaseConfigurations ::HashConfig . new (
17
+ config . env_name ,
18
+ config . name ,
19
+ config . configuration_hash . merge (
20
+ checkout_timeout : 0.2 , # Reduce checkout_timeout to speedup tests
21
+ )
22
+ )
23
+
16
24
@pool_config = ActiveRecord ::ConnectionAdapters ::PoolConfig . new ( ActiveRecord ::Base , @db_config , :writing , :default )
17
25
@pool = ConnectionPool . new ( @pool_config )
18
26
@@ -436,7 +444,7 @@ def test_checkout_fairness
436
444
end
437
445
438
446
# this should wake up the waiting threads one by one in order
439
- conns . each { |conn | @pool . checkin ( conn ) ; sleep 0.1 }
447
+ conns . each { |conn | @pool . checkin ( conn ) ; sleep 0.01 }
440
448
441
449
dispose_held_connections . set
442
450
threads . each ( &:join )
@@ -768,11 +776,11 @@ def test_connection_pool_stat
768
776
with_single_connection_pool do |pool |
769
777
pool . with_connection do |connection |
770
778
stats = pool . stat
771
- assert_equal ( { size : 1 , connections : 1 , busy : 1 , dead : 0 , idle : 0 , waiting : 0 , checkout_timeout : 5 } , stats )
779
+ assert_equal ( { size : 1 , connections : 1 , busy : 1 , dead : 0 , idle : 0 , waiting : 0 , checkout_timeout : 0.2 } , stats )
772
780
end
773
781
774
782
stats = pool . stat
775
- assert_equal ( { size : 1 , connections : 1 , busy : 0 , dead : 0 , idle : 1 , waiting : 0 , checkout_timeout : 5 } , stats )
783
+ assert_equal ( { size : 1 , connections : 1 , busy : 0 , dead : 0 , idle : 1 , waiting : 0 , checkout_timeout : 0.2 } , stats )
776
784
777
785
assert_raise ( ThreadError ) do
778
786
new_thread do
@@ -782,7 +790,7 @@ def test_connection_pool_stat
782
790
end
783
791
784
792
stats = pool . stat
785
- assert_equal ( { size : 1 , connections : 1 , busy : 0 , dead : 1 , idle : 0 , waiting : 0 , checkout_timeout : 5 } , stats )
793
+ assert_equal ( { size : 1 , connections : 1 , busy : 0 , dead : 1 , idle : 0 , waiting : 0 , checkout_timeout : 0.2 } , stats )
786
794
ensure
787
795
Thread . report_on_exception = original_report_on_exception
788
796
end
0 commit comments