Browse files

Fix just-plain-wrongness of psql auto-reconnect test.

Full test requiring manual intervention was fine, but
w/ simulated disconnect, assertion was backward & still
passing. Was several kinds of wrong.
  • Loading branch information...
1 parent 481dac9 commit c381d5cbf959208adeb38e7859ee815dfbd2cf54 Steve Jorgensen committed Aug 7, 2012
Showing with 9 additions and 8 deletions.
  1. +9 −8 activerecord/test/cases/adapters/postgresql/connection_test.rb
View
17 activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -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
@@ -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

0 comments on commit c381d5c

Please sign in to comment.