def test_get_query_embedding_retry_exhausted(
    mock_retry_decorator, mock_get_embedding, embedding_instance
):
    """Test retry mechanism exhausts all retries in _get_query_embedding."""

    # Mock the retry decorator to simulate retries without delays
    def retry_decorator_simulation(func):
        def wrapper(*args, **kwargs):
            attempts = 0
            while attempts < embedding_instance.max_retries:
                try:
                    return func(*args, **kwargs)
                except Exception:
                    attempts += 1
                    if attempts == embedding_instance.max_retries:
                        raise

            return None

        return wrapper

    mock_retry_decorator.side_effect = lambda **kwargs: retry_decorator_simulation

    # Simulate persistent failures
    mock_get_embedding.side_effect = Exception("Persistent error")

    query = "test query"

    # Call the method under test and expect an exception
    with pytest.raises(Exception, match="Persistent error"):
        embedding_instance._get_query_embedding(query)

    # Assert the embedding function was retried the maximum number of times
    assert mock_get_embedding.call_count == embedding_instance.max_retries
    mock_get_embedding.assert_called_with(
        embedding_instance._get_client(),
        query,
        engine=embedding_instance._query_engine,
        **embedding_instance.additional_kwargs,
    )
Test retry mechanism exhausts all retries in _get_query_embedding.
llama-index-integrations/embeddings/llama-index-embeddings-openai/tests/test_embeddings_openai.py