Skip to content

Commit 6ebcde8

Browse files
authored
Fixing flaky test test_resuming_crashed_index_build by retrying (#837)
1 parent c8746a3 commit 6ebcde8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/test_agents.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import shutil
1010
import tempfile
1111
import time
12+
import zlib
1213
from copy import deepcopy
1314
from functools import wraps
1415
from pathlib import Path
@@ -25,6 +26,7 @@
2526
from llmclient import CommonLLMNames, EmbeddingModel, MultipleCompletionLLMModel
2627
from pytest_subtests import SubTests
2728
from tantivy import Index
29+
from tenacity import Retrying, retry_if_exception_type, stop_after_attempt
2830

2931
from paperqa.agents import SearchIndex, agent_query
3032
from paperqa.agents.env import (
@@ -147,8 +149,18 @@ async def crashing_aadd(*args, **kwargs) -> str | None:
147149
mock_aadd.assert_awaited()
148150

149151
# 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)
152164
assert (
153165
mock_aadd.await_count <= crash_threshold
154166
), "Should have been able to resume build"

0 commit comments

Comments
 (0)