3 class PooledConnectionsTest
< ActiveRecord
::TestCase
6 @connection = ActiveRecord
::Base.remove_connection
10 ActiveRecord
::Base.clear_all_connections
!
11 ActiveRecord
::Base.establish_connection(@connection)
15 def checkout_connections
16 ActiveRecord
::Base.establish_connection(@connection.merge({:pool => 2, :wait_timeout => 0.3}))
23 @connections << ActiveRecord
::Base.connection_pool
.checkout
24 rescue ActiveRecord
::ConnectionTimeoutError
31 # Will deadlock due to lack of Monitor timeouts in 1.9
32 if RUBY_VERSION < '1.9'
33 def test_pooled_connection_checkout
35 assert_equal
@connections.length
, 2
36 assert_equal
@timed_out, 2
40 def checkout_checkin_connections(pool_size
, threads
)
41 ActiveRecord
::Base.establish_connection(@connection.merge({:pool => pool_size
, :wait_timeout => 0.5}))
47 conn
= ActiveRecord
::Base.connection_pool
.checkout
49 ActiveRecord
::Base.connection_pool
.checkin conn
50 @connection_count += 1
51 rescue ActiveRecord
::ConnectionTimeoutError
58 def test_pooled_connection_checkin_one
59 checkout_checkin_connections
1, 2
60 assert_equal
2, @connection_count
61 assert_equal
0, @timed_out
64 def test_pooled_connection_checkin_two
65 checkout_checkin_connections
2, 3
66 assert_equal
3, @connection_count
67 assert_equal
0, @timed_out
70 def test_pooled_connection_checkout_existing_first
71 ActiveRecord
::Base.establish_connection(@connection.merge({:pool => 1}))
72 conn_pool
= ActiveRecord
::Base.connection_pool
73 conn
= conn_pool
.checkout
74 conn_pool
.checkin(conn
)
75 conn
= conn_pool
.checkout
76 assert ActiveRecord
::ConnectionAdapters::AbstractAdapter === conn
77 conn_pool
.checkin(conn
)
80 def test_not_connected_defined_connection_returns_false
81 ActiveRecord
::Base.establish_connection(@connection)
82 assert
! ActiveRecord
::Base.connected
?
85 def test_undefined_connection_returns_false
86 old_handler
= ActiveRecord
::Base.connection_handler
87 ActiveRecord
::Base.connection_handler
= ActiveRecord
::ConnectionAdapters::ConnectionHandler.new
88 assert_equal
false, ActiveRecord
::Base.connected
?
90 ActiveRecord
::Base.connection_handler
= old_handler
92 end unless %w(FrontBase
).include? ActiveRecord
::Base.connection
.adapter_name
94 class AllowConcurrencyDeprecatedTest
< ActiveRecord
::TestCase
95 def test_allow_concurrency_is_deprecated
96 assert_deprecated('ActiveRecord::Base.allow_concurrency') do
97 ActiveRecord
::Base.allow_concurrency
99 assert_deprecated('ActiveRecord::Base.allow_concurrency=') do
100 ActiveRecord
::Base.allow_concurrency
= true