From 575e209f7020a327b3347368eb29e2cc9d01ac71 Mon Sep 17 00:00:00 2001 From: Stefano Fiorucci Date: Wed, 12 Jun 2024 19:17:53 +0200 Subject: [PATCH] tests: Pinecone - fix `test_serverless_index_creation_from_scratch` (#806) * pinecone tests: wait for index creation * make index name dynamic * lint * run the test only once in our suite * add reason * increase sleep time * better skipif condition * better coverage options * fix * revert changes in coverage.run * fix * add unit to sleep tima * define index name in the matrix * fix * add default * lint --- .github/workflows/pinecone.yml | 8 ++++++++ integrations/pinecone/tests/conftest.py | 10 +++++----- integrations/pinecone/tests/test_document_store.py | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pinecone.yml b/.github/workflows/pinecone.yml index 85f36ae5d..b26f2a793 100644 --- a/.github/workflows/pinecone.yml +++ b/.github/workflows/pinecone.yml @@ -33,6 +33,12 @@ jobs: # Pinecone tests are time expensive, so the matrix is limited to Python 3.9 and 3.10 os: [ubuntu-latest] python-version: ["3.9", "3.10"] + # the INDEX_NAME is used in test_serverless_index_creation_from_scratch + include: + - python-version: "3.9" + INDEX_NAME: "index-39" + - python-version: "3.10" + INDEX_NAME: "index-310" steps: - uses: actions/checkout@v4 @@ -56,6 +62,8 @@ jobs: - name: Run tests id: tests + env: + INDEX_NAME: ${{ matrix.INDEX_NAME }} run: hatch run cov - name: Nightly - run unit tests with Haystack main branch diff --git a/integrations/pinecone/tests/conftest.py b/integrations/pinecone/tests/conftest.py index 6c3f7f39b..b19f0a807 100644 --- a/integrations/pinecone/tests/conftest.py +++ b/integrations/pinecone/tests/conftest.py @@ -6,13 +6,13 @@ from haystack_integrations.document_stores.pinecone import PineconeDocumentStore -# This is the approximate time it takes for the documents to be available -SLEEP_TIME = 10 +# This is the approximate time in seconds it takes for the documents to be available +SLEEP_TIME_IN_SECONDS = 15 @pytest.fixture() def sleep_time(): - return SLEEP_TIME + return SLEEP_TIME_IN_SECONDS @pytest.fixture @@ -37,14 +37,14 @@ def document_store(request): def write_documents_and_wait(documents, policy=DuplicatePolicy.NONE): written_docs = original_write_documents(documents, policy) - time.sleep(SLEEP_TIME) + time.sleep(SLEEP_TIME_IN_SECONDS) return written_docs original_delete_documents = store.delete_documents def delete_documents_and_wait(filters): original_delete_documents(filters) - time.sleep(SLEEP_TIME) + time.sleep(SLEEP_TIME_IN_SECONDS) store.write_documents = write_documents_and_wait store.delete_documents = delete_documents_and_wait diff --git a/integrations/pinecone/tests/test_document_store.py b/integrations/pinecone/tests/test_document_store.py index 459401800..90ce2ccff 100644 --- a/integrations/pinecone/tests/test_document_store.py +++ b/integrations/pinecone/tests/test_document_store.py @@ -145,7 +145,10 @@ def test_convert_dict_spec_to_pinecone_object_fail(): @pytest.mark.integration @pytest.mark.skipif("PINECONE_API_KEY" not in os.environ, reason="PINECONE_API_KEY not set") def test_serverless_index_creation_from_scratch(sleep_time): - index_name = "my-serverless-index" + # we use a fixed index name to avoid hitting the limit of Pinecone's free tier (max 5 indexes) + # the index name is defined in the test matrix of the GitHub Actions workflow + # the default value is provided for local testing + index_name = os.environ.get("INDEX_NAME", "serverless-test-index") client = Pinecone(api_key=os.environ["PINECONE_API_KEY"]) try: