Skip to content

Commit ce20701

Browse files
authored
test: Pinecone - improve flaky tests (#2787)
* test: Pinecone - try to fix flaky tests * improvs
1 parent 53989b1 commit ce20701

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

integrations/pinecone/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ all = 'pytest {args:tests}'
7171

7272
# Pinecone tests are slow (require HTTP requests), so we run them in parallel
7373
# with pytest-xdist (https://pytest-xdist.readthedocs.io/en/stable/distribution.html)
74-
cov-retry = 'pytest -n auto --maxprocesses=2 --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
74+
cov-retry = 'pytest -n auto --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
7575

7676
types = """mypy -p haystack_integrations.components.retrievers.pinecone \
7777
-p haystack_integrations.document_stores.pinecone {args}"""

integrations/pinecone/tests/conftest.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
from haystack_integrations.document_stores.pinecone import PineconeDocumentStore
1111

1212
# This is the approximate time in seconds it takes for the documents to be available
13-
SLEEP_TIME_IN_SECONDS = 25
13+
WRITE_SLEEP_TIME_IN_SECONDS = 25
14+
DELETE_SLEEP_TIME_IN_SECONDS = 30
1415

1516

1617
@pytest.fixture()
17-
def sleep_time():
18-
return SLEEP_TIME_IN_SECONDS
18+
def delete_sleep_time():
19+
return DELETE_SLEEP_TIME_IN_SECONDS
1920

2021

2122
@pytest.fixture
@@ -40,14 +41,14 @@ def document_store(request):
4041

4142
def write_documents_and_wait(documents, policy=DuplicatePolicy.NONE):
4243
written_docs = original_write_documents(documents, policy)
43-
time.sleep(SLEEP_TIME_IN_SECONDS)
44+
time.sleep(WRITE_SLEEP_TIME_IN_SECONDS)
4445
return written_docs
4546

4647
original_delete_documents = store.delete_documents
4748

4849
def delete_documents_and_wait(filters):
4950
original_delete_documents(filters)
50-
time.sleep(SLEEP_TIME_IN_SECONDS)
51+
time.sleep(DELETE_SLEEP_TIME_IN_SECONDS)
5152

5253
store.write_documents = write_documents_and_wait
5354
store.delete_documents = delete_documents_and_wait
@@ -81,14 +82,14 @@ async def document_store_async(request):
8182

8283
async def write_documents_and_wait_async(documents, policy=DuplicatePolicy.NONE):
8384
written_docs = await original_write_documents(documents, policy)
84-
await asyncio.sleep(SLEEP_TIME_IN_SECONDS)
85+
await asyncio.sleep(WRITE_SLEEP_TIME_IN_SECONDS)
8586
return written_docs
8687

8788
original_delete_documents = store.delete_documents_async
8889

8990
async def delete_documents_and_wait_async(filters):
9091
await original_delete_documents(filters)
91-
await asyncio.sleep(SLEEP_TIME_IN_SECONDS)
92+
await asyncio.sleep(DELETE_SLEEP_TIME_IN_SECONDS)
9293

9394
store.write_documents_async = write_documents_and_wait_async
9495
store.delete_documents_async = delete_documents_and_wait_async

integrations/pinecone/tests/test_document_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_convert_meta_to_int():
217217

218218
@pytest.mark.integration
219219
@pytest.mark.skipif(not os.environ.get("PINECONE_API_KEY"), reason="PINECONE_API_KEY not set")
220-
def test_serverless_index_creation_from_scratch(sleep_time):
220+
def test_serverless_index_creation_from_scratch(delete_sleep_time):
221221
# we use a fixed index name to avoid hitting the limit of Pinecone's free tier (max 5 indexes)
222222
# the index name is defined in the test matrix of the GitHub Actions workflow
223223
# the default value is provided for local testing
@@ -229,7 +229,7 @@ def test_serverless_index_creation_from_scratch(sleep_time):
229229
except Exception: # noqa S110
230230
pass
231231

232-
time.sleep(sleep_time)
232+
time.sleep(delete_sleep_time)
233233

234234
ds = PineconeDocumentStore(
235235
index=index_name,

0 commit comments

Comments
 (0)