|
3 | 3 | from unittest.mock import patch
|
4 | 4 |
|
5 | 5 | import pytest
|
| 6 | +from pytest_socket import SocketBlockedError |
6 | 7 |
|
7 | 8 | from langchain_community.vectorstores.azuresearch import AzureSearch
|
8 | 9 | from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
|
@@ -192,6 +193,40 @@ def mock_create_index() -> None:
|
192 | 193 | assert vector_store.client._api_version == "test"
|
193 | 194 |
|
194 | 195 |
|
| 196 | +@pytest.mark.requires("azure.search.documents") |
| 197 | +def test_additional_search_options_retry_policy() -> None: |
| 198 | + """ |
| 199 | + Reproduces bug captured in: |
| 200 | + https://github.com/langchain-ai/langchain-community/issues/76 |
| 201 | + """ |
| 202 | + from azure.core.exceptions import HttpResponseError |
| 203 | + from azure.core.pipeline.policies import RetryPolicy |
| 204 | + from azure.search.documents.indexes import SearchIndexClient |
| 205 | + |
| 206 | + def mock_create_index() -> None: |
| 207 | + pytest.fail("Should not create index in this test") |
| 208 | + |
| 209 | + with patch.multiple( |
| 210 | + SearchIndexClient, get_index=mock_default_index, create_index=mock_create_index |
| 211 | + ): |
| 212 | + vector_store = create_vector_store( |
| 213 | + additional_search_client_options={ |
| 214 | + "retry_policy": RetryPolicy( |
| 215 | + total_retries=3, |
| 216 | + backoff_factor=0.5, |
| 217 | + timeout=5, |
| 218 | + ), |
| 219 | + } |
| 220 | + ) |
| 221 | + assert vector_store.client is not None |
| 222 | + |
| 223 | + # Bug previously raised an: |
| 224 | + # AttributeError: 'coroutine' object has no attribute 'http_response'. |
| 225 | + # Expect a network connection to be made (and blocked). |
| 226 | + with pytest.raises((HttpResponseError, SocketBlockedError)): |
| 227 | + list(vector_store.client.search()) |
| 228 | + |
| 229 | + |
195 | 230 | @pytest.mark.requires("azure.search.documents")
|
196 | 231 | def test_ids_used_correctly() -> None:
|
197 | 232 | """Check whether vector store uses the document ids when provided with them."""
|
|
0 commit comments