Skip to content

Commit

Permalink
tests: Pinecone - fix test_serverless_index_creation_from_scratch (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
anakin87 authored Jun 12, 2024
1 parent 015cc3e commit 575e209
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pinecone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions integrations/pinecone/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion integrations/pinecone/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 575e209

Please sign in to comment.