Skip to content
Browse files

Terminate the backend ourselves on PG 9.2+

This should make it harder to accidentally break this test.
  • Loading branch information...
1 parent 6ebc07b commit e1c2b8a232de2ac17644d7b4d433833a198579e8 @matthewd matthewd committed Dec 19, 2013
Showing with 17 additions and 7 deletions.
  1. +17 −7 activerecord/test/cases/adapters/postgresql/connection_test.rb
View
24 activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -81,24 +81,34 @@ def test_schema_names_logs_name
assert_equal 'SCHEMA', @connection.logged[0][1]
end
- # Must have with_manual_interventions set to true for this
- # test to run.
+ # Must have PostgreSQL >= 9.2, or with_manual_interventions set to
+ # true for this test to run.
+ #
# When prompted, restart the PostgreSQL server with the
# "-m fast" option or kill the individual connection assuming
# you know the incantation to do that.
# To restart PostgreSQL 9.1 on OS X, installed via MacPorts, ...
# sudo su postgres -c "pg_ctl restart -D /opt/local/var/db/postgresql91/defaultdb/ -m fast"
def test_reconnection_after_actual_disconnection_with_verify
- skip "with_manual_interventions is false in configuration" unless ARTest.config['with_manual_interventions']
-
original_connection_pid = @connection.query('select pg_backend_pid()')
# Sanity check.
assert @connection.active?
- puts 'Kill the connection now (e.g. by restarting the PostgreSQL ' +
- 'server with the "-m fast" option) and then press enter.'
- $stdin.gets
+ if @connection.send(:postgresql_version) >= 90200
+ secondary_connection = ActiveRecord::Base.connection_pool.checkout
+ secondary_connection.query("select pg_terminate_backend(#{original_connection_pid.first.first})")
+ ActiveRecord::Base.connection_pool.checkin(secondary_connection)
+ elsif ARTest.config['with_manual_interventions']
+ puts 'Kill the connection now (e.g. by restarting the PostgreSQL ' +
+ 'server with the "-m fast" option) and then press enter.'
+ $stdin.gets
+ else
+ # We're not capable of terminating the backend ourselves, and
+ # we're not allowed to seek assistance; bail out without
+ # actually testing anything.
+ return
+ end
@connection.verify!

0 comments on commit e1c2b8a

Please sign in to comment.
Something went wrong with that request. Please try again.