Skip to content

Commit

Permalink
Fix just-plain-wrongness of psql auto-reconnect test.
Browse files Browse the repository at this point in the history
Full test requiring manual intervention was fine, but
w/ simulated disconnect, assertion was backward & still
passing. Was several kinds of wrong.
  • Loading branch information
Steve Jorgensen committed Aug 7, 2012
1 parent 481dac9 commit c381d5c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions activerecord/test/cases/adapters/postgresql/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ def test_reconnection_after_simulated_disconnection_with_verify
assert @connection.active?
original_connection_pid = @connection.query('select pg_backend_pid()')

# Fail with bad connection after next query attempt.
connection_class = class << @connection ; self ; end
connection_class.class_eval <<-CODE
# Fail with bad connection on next query attempt.
raw_connection = @connection.raw_connection
raw_connection_class = class << raw_connection ; self ; end
raw_connection_class.class_eval <<-CODE, __FILE__, __LINE__ + 1
def query_fake(*args)
if @called ||= false
@connection.stubs(:status).returns(PCconn::CONNECTION_BAD)
if !( @called ||= false )
self.stubs(:status).returns(PGconn::CONNECTION_BAD)
raise PGError
else
@called = true
@connection.unstub(:status)
self.unstub(:status)
query_unfake(*args)
end
end
Expand All @@ -107,13 +108,13 @@ def query_fake(*args)
@connection.verify!
new_connection_pid = @connection.query('select pg_backend_pid()')
ensure
connection_class.class_eval <<-CODE
raw_connection_class.class_eval <<-CODE
alias query query_unfake
undef query_fake
CODE
end

assert_equal original_connection_pid, new_connection_pid, "Should have a new underlying connection pid"
assert_not_equal original_connection_pid, new_connection_pid, "Should have a new underlying connection pid"
end

# Must have with_manual_interventions set to true for this
Expand Down

0 comments on commit c381d5c

Please sign in to comment.