From 4930d46dfcdd164a37b516ece9c57dac655750ad Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Sun, 5 Jan 2025 15:02:40 +0400 Subject: [PATCH] fix: pinecone delays --- tests/unit/test_router.py | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/tests/unit/test_router.py b/tests/unit/test_router.py index 6848a430..4d1378c5 100644 --- a/tests/unit/test_router.py +++ b/tests/unit/test_router.py @@ -752,37 +752,30 @@ def test_query_filter(self, routes, index_cls, encoder_cls, router_cls): ) if index_cls is PineconeIndex: time.sleep(PINECONE_SLEEP) # allow for index to be populated - query_result = route_layer(text="Hello", route_filter=["Route 1"]).name + # with pytest.raises(ValueError): + # # Route 8 does not exist so should raise ValueError + # route_layer(text="Hello", route_filter=["Route 8"]).name try: + # TODO JB: currently LocalIndex raises ValueError but others don't + # they should all behave in the same way route_layer(text="Hello", route_filter=["Route 8"]).name except ValueError: assert True - assert query_result in ["Route 1"] - - @pytest.mark.skipif( - os.environ.get("PINECONE_API_KEY") is None, reason="Pinecone API key required" - ) - def test_query_filter_pinecone(self, routes, index_cls, encoder_cls, router_cls): - if index_cls is PineconeIndex: - encoder = encoder_cls() - pineconeindex = init_index(index_cls, index_name=encoder.__class__.__name__) - route_layer = router_cls( - encoder=encoder, - routes=routes, - index=pineconeindex, - auto_sync="local", - ) - time.sleep(PINECONE_SLEEP) # allow for index to be populated + count = 0 + # we allow for 5 retries to allow for index to be populated + while count < RETRY_COUNT: query_result = route_layer(text="Hello", route_filter=["Route 1"]).name - try: - route_layer(text="Hello", route_filter=["Route 8"]).name - except ValueError: - assert True - - assert query_result in ["Route 1"] + assert query_result in ["Route 1"] + break + except AssertionError: + logger.warning( + f"Query result not in expected routes, waiting for retry (try {count})" + ) + count += 1 + time.sleep(PINECONE_SLEEP) # allow for index to be populated @pytest.mark.skipif( os.environ.get("PINECONE_API_KEY") is None, reason="Pinecone API key required"