|
9 | 9 | import shutil |
10 | 10 | import tempfile |
11 | 11 | import time |
| 12 | +import zlib |
12 | 13 | from copy import deepcopy |
13 | 14 | from functools import wraps |
14 | 15 | from pathlib import Path |
|
25 | 26 | from llmclient import CommonLLMNames, EmbeddingModel, MultipleCompletionLLMModel |
26 | 27 | from pytest_subtests import SubTests |
27 | 28 | from tantivy import Index |
| 29 | +from tenacity import Retrying, retry_if_exception_type, stop_after_attempt |
28 | 30 |
|
29 | 31 | from paperqa.agents import SearchIndex, agent_query |
30 | 32 | from paperqa.agents.env import ( |
@@ -147,8 +149,18 @@ async def crashing_aadd(*args, **kwargs) -> str | None: |
147 | 149 | mock_aadd.assert_awaited() |
148 | 150 |
|
149 | 151 | # 2. Resume and complete building the index |
150 | | - with patch.object(Docs, "aadd", autospec=True, side_effect=Docs.aadd) as mock_aadd: |
151 | | - index = await get_directory_index(settings=agent_test_settings) |
| 152 | + for attempt in Retrying( |
| 153 | + stop=stop_after_attempt(3), |
| 154 | + # zlib.error: Error -5 while decompressing data: incomplete or truncated stream |
| 155 | + retry=retry_if_exception_type(zlib.error), |
| 156 | + ): |
| 157 | + with ( |
| 158 | + attempt, |
| 159 | + patch.object( |
| 160 | + Docs, "aadd", autospec=True, side_effect=Docs.aadd |
| 161 | + ) as mock_aadd, |
| 162 | + ): |
| 163 | + index = await get_directory_index(settings=agent_test_settings) |
152 | 164 | assert ( |
153 | 165 | mock_aadd.await_count <= crash_threshold |
154 | 166 | ), "Should have been able to resume build" |
|
0 commit comments