Merge pull request #14035 from matthewd/pg_terminate_backend
Terminate the backend ourselves on PG 9.2+
This commit is contained in:
commit
6e61da2dab
@ -91,40 +91,50 @@ def test_statement_key_is_logged
|
||||
assert_operator plan.length, :>, 0
|
||||
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"
|
||||
if ARTest.config['with_manual_interventions']
|
||||
def test_reconnection_after_actual_disconnection_with_verify
|
||||
original_connection_pid = @connection.query('select pg_backend_pid()')
|
||||
def test_reconnection_after_actual_disconnection_with_verify
|
||||
original_connection_pid = @connection.query('select pg_backend_pid()')
|
||||
|
||||
# Sanity check.
|
||||
assert @connection.active?
|
||||
# Sanity check.
|
||||
assert @connection.active?
|
||||
|
||||
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!
|
||||
@connection.verify!
|
||||
|
||||
assert @connection.active?
|
||||
assert @connection.active?
|
||||
|
||||
# If we get no exception here, then either we re-connected successfully, or
|
||||
# we never actually got disconnected.
|
||||
new_connection_pid = @connection.query('select pg_backend_pid()')
|
||||
# If we get no exception here, then either we re-connected successfully, or
|
||||
# we never actually got disconnected.
|
||||
new_connection_pid = @connection.query('select pg_backend_pid()')
|
||||
|
||||
assert_not_equal original_connection_pid, new_connection_pid,
|
||||
"umm -- looks like you didn't break the connection, because we're still " +
|
||||
"successfully querying with the same connection pid."
|
||||
assert_not_equal original_connection_pid, new_connection_pid,
|
||||
"umm -- looks like you didn't break the connection, because we're still " +
|
||||
"successfully querying with the same connection pid."
|
||||
|
||||
# Repair all fixture connections so other tests won't break.
|
||||
@fixture_connections.each do |c|
|
||||
c.verify!
|
||||
end
|
||||
# Repair all fixture connections so other tests won't break.
|
||||
@fixture_connections.each do |c|
|
||||
c.verify!
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user