diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-17 17:13:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-03-17 17:13:00 -0700 |
commit | 8f218266bb4fa4ef2a07904b106c72fda9e182a6 (patch) | |
tree | 3065ab1e65e9577c11e04d51f12c56e4da4dba69 /activerecord/test/cases | |
parent | 4a69c933cf07ee296a4ae1e2612c31922019eeab (diff) | |
parent | 9e457a8654fa89fe329719f88ae3679aefb21e56 (diff) | |
download | rails-8f218266bb4fa4ef2a07904b106c72fda9e182a6.tar.gz rails-8f218266bb4fa4ef2a07904b106c72fda9e182a6.tar.bz2 rails-8f218266bb4fa4ef2a07904b106c72fda9e182a6.zip |
Merge pull request #14360 from matthewd/thread_aware_reaper
Track owning thread for connection pool
Diffstat (limited to 'activerecord/test/cases')
4 files changed, 55 insertions, 22 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 4715fa002d..aa4996133f 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -45,6 +45,37 @@ module ActiveRecord assert_equal 'off', expect end + def test_reset + @connection.query('ROLLBACK') + @connection.query('SET geqo TO off') + + # Verify the setting has been applied. + expect = @connection.query('show geqo').first.first + assert_equal 'off', expect + + @connection.reset! + + # Verify the setting has been cleared. + expect = @connection.query('show geqo').first.first + assert_equal 'on', expect + end + + def test_reset_with_transaction + @connection.query('ROLLBACK') + @connection.query('SET geqo TO off') + + # Verify the setting has been applied. + expect = @connection.query('show geqo').first.first + assert_equal 'off', expect + + @connection.query('BEGIN') + @connection.reset! + + # Verify the setting has been cleared. + expect = @connection.query('show geqo').first.first + assert_equal 'on', expect + end + def test_tables_logs_name @connection.tables('hello') assert_equal 'SCHEMA', @subscriber.logged[0][1] diff --git a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb index eb2fe5639b..deed226eab 100644 --- a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb +++ b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb @@ -29,12 +29,6 @@ module ActiveRecord assert_not adapter.lease, 'should not lease adapter' end - def test_last_use - assert_not adapter.last_use - adapter.lease - assert adapter.last_use - end - def test_expire_mutates_in_use assert adapter.lease, 'lease adapter' assert adapter.in_use?, 'adapter is in use' diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index c4108ad7f6..6300011f4a 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -124,7 +124,6 @@ module ActiveRecord @pool.checkout @pool.checkout @pool.checkout - @pool.dead_connection_timeout = 0 connections = @pool.connections.dup @@ -134,21 +133,25 @@ module ActiveRecord end def test_reap_inactive + ready = false @pool.checkout - @pool.checkout - @pool.checkout - @pool.dead_connection_timeout = 0 - - connections = @pool.connections.dup - connections.each do |conn| - conn.extend(Module.new { def active_threadsafe?; false; end; }) + child = Thread.new do + @pool.checkout + @pool.checkout + ready = true + Thread.stop end + Thread.pass until ready + + assert_equal 3, active_connections(@pool).size + child.terminate + child.join @pool.reap - assert_equal 0, @pool.connections.length + assert_equal 1, active_connections(@pool).size ensure - connections.each(&:close) + @pool.connections.each(&:close) end def test_remove_connection diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb index 015c37cce8..f52fd22489 100644 --- a/activerecord/test/cases/reaper_test.rb +++ b/activerecord/test/cases/reaper_test.rb @@ -63,17 +63,22 @@ module ActiveRecord spec.config[:reaping_frequency] = 0.0001 pool = ConnectionPool.new spec - pool.dead_connection_timeout = 0 - conn = pool.checkout - count = pool.connections.length + conn = nil + child = Thread.new do + conn = pool.checkout + Thread.stop + end + Thread.pass while conn.nil? + + assert conn.in_use? - conn.extend(Module.new { def active_threadsafe?; false; end; }) + child.terminate - while count == pool.connections.length + while conn.in_use? Thread.pass end - assert_equal(count - 1, pool.connections.length) + assert !conn.in_use? end end end |