def test_timeout_getting_connection_from_pool(self): session = self.make_basic_session() session.cluster._default_load_balancing_policy.make_query_plan.return_value = [ 'ip1', 'ip2' ] # the first pool will raise an exception on borrow_connection() exc = NoConnectionsAvailable() first_pool = Mock(is_shutdown=False) first_pool.borrow_connection.side_effect = exc # the second pool will return a connection second_pool = Mock(is_shutdown=False) connection = Mock(spec=Connection) second_pool.borrow_connection.return_value = (connection, 1) session._pools.get.side_effect = [first_pool, second_pool] rf = self.make_response_future(session) rf.send_request() rf._set_result(None, None, None, self.make_mock_response([{ 'col': 'val' }])) self.assertEqual(rf.result(), [{'col': 'val'}]) # make sure the exception is recorded correctly self.assertEqual(rf._errors, {'ip1': exc})
def test_timeout_getting_connection_from_pool(self): session = self.make_basic_session() session._load_balancer.make_query_plan.return_value = ['ip1', 'ip2'] # the first pool will raise an exception on borrow_connection() exc = NoConnectionsAvailable() first_pool = Mock(is_shutdown=False) first_pool.borrow_connection.side_effect = exc second_pool = Mock(is_shutdown=False) session._pools.get.side_effect = [first_pool, second_pool] rf = self.make_response_future(session) rf.send_request() response = Mock(spec=ResultMessage, kind=ResultMessage.KIND_ROWS, results=[{ 'col': 'val' }]) rf._set_result(response) self.assertEqual(rf.result(), [{'col': 'val'}]) # make sure the exception is recorded correctly self.assertEqual(rf._errors, {'ip1': exc})