def test_pre_ping_weakref_finalizer(self): pool = self._pool_fixture(pre_ping=True) conn = pool.connect() old_dbapi_conn = conn.connection conn.close() eq_(old_dbapi_conn.mock_calls, [call.cursor(), call.rollback()]) self.dbapi.shutdown("execute", stop=True) self.dbapi.restart() conn = pool.connect() dbapi_conn = conn.connection del conn gc_collect() # new connection was reset on return appropriately eq_(dbapi_conn.mock_calls, [call.cursor(), call.rollback()]) # old connection was just closed - did not get an # erroneous reset on return eq_( old_dbapi_conn.mock_calls, [call.cursor(), call.rollback(), call.cursor(), call.close()], )
def test_ping_not_on_first_connect(self): pool = self._pool_fixture(pre_ping=True, pool_kw=dict(pool_size=1, max_overflow=0)) conn = pool.connect() dbapi_conn = conn.connection eq_(dbapi_conn.mock_calls, []) conn.close() # no ping, so no cursor() call. eq_(dbapi_conn.mock_calls, [call.rollback()]) conn = pool.connect() is_(conn.connection, dbapi_conn) # ping, so cursor() call. eq_(dbapi_conn.mock_calls, [call.rollback(), call.cursor()]) conn.close() conn = pool.connect() is_(conn.connection, dbapi_conn) # ping, so cursor() call. eq_( dbapi_conn.mock_calls, [call.rollback(), call.cursor(), call.rollback(), call.cursor()], ) conn.close()
def test_ping_not_on_reconnect(self): pool = self._pool_fixture(pre_ping=True, pool_kw=dict(pool_size=1, max_overflow=0)) conn = pool.connect() dbapi_conn = conn.connection conn_rec = conn._connection_record eq_(dbapi_conn.mock_calls, []) conn.close() conn = pool.connect() is_(conn.connection, dbapi_conn) # ping, so cursor() call. eq_(dbapi_conn.mock_calls, [call.rollback(), call.cursor()]) conn.invalidate() is_(conn.connection, None) # connect again, make sure we're on the same connection record conn = pool.connect() is_(conn._connection_record, conn_rec) # no ping dbapi_conn = conn.connection eq_(dbapi_conn.mock_calls, [])