|
1 | | -from unittest.mock import MagicMock, patch |
| 1 | +from unittest.mock import AsyncMock, MagicMock, patch |
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | import pytest_asyncio |
@@ -162,6 +162,29 @@ async def test_metadata_methods_async_absorb_client_errors(self, method_name, ar |
162 | 162 | ): |
163 | 163 | assert await getattr(document_store, method_name)(*args) == expected |
164 | 164 |
|
| 165 | + async def test_close_async(self): |
| 166 | + document_store = QdrantDocumentStore(location=":memory:") |
| 167 | + mock_client = AsyncMock() |
| 168 | + document_store._async_client = mock_client |
| 169 | + |
| 170 | + await document_store.close_async() |
| 171 | + |
| 172 | + mock_client.close.assert_awaited_once() |
| 173 | + assert document_store._async_client is None |
| 174 | + |
| 175 | + await document_store.close_async() |
| 176 | + mock_client.close.assert_awaited_once() |
| 177 | + |
| 178 | + async def test_close_async_is_exception_safe(self): |
| 179 | + document_store = QdrantDocumentStore(location=":memory:") |
| 180 | + mock_client = AsyncMock() |
| 181 | + mock_client.close.side_effect = RuntimeError("boom") |
| 182 | + document_store._async_client = mock_client |
| 183 | + |
| 184 | + await document_store.close_async() |
| 185 | + |
| 186 | + assert document_store._async_client is None |
| 187 | + |
165 | 188 |
|
166 | 189 | @pytest.mark.integration |
167 | 190 | @pytest.mark.asyncio |
@@ -195,6 +218,16 @@ def assert_documents_are_equal(self, received: list[Document], expected: list[Do |
195 | 218 | assert len(received) == len(expected) |
196 | 219 | assert {doc.id for doc in received} == {doc.id for doc in expected} |
197 | 220 |
|
| 221 | + async def test_close_async_and_reopen(self, document_store: QdrantDocumentStore): |
| 222 | + assert await document_store.count_documents_async() == 0 |
| 223 | + assert document_store._async_client is not None |
| 224 | + |
| 225 | + await document_store.close_async() |
| 226 | + |
| 227 | + assert document_store._async_client is None |
| 228 | + assert await document_store.count_documents_async() == 0 |
| 229 | + assert document_store._async_client is not None |
| 230 | + |
198 | 231 | @pytest.mark.asyncio |
199 | 232 | async def test_write_documents_async(self, document_store: QdrantDocumentStore): |
200 | 233 | docs = [Document(id="1")] |
|
0 commit comments