This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameterize [server, pod] and [namespace] across all tests (#250)
* [test] run E2E test on both serverless and pod Since we had a single index_name fixture - both tests were trying to create an index with the same name simulteneously * [test] Parameterize tests over [serverless, pod] I've created a centralized conftest.py across all tests (e2e and system) with parametrized fixtures - index_params and namespace. Now all tests can simply depend on these fixtures to be parameterized * Make linter happy * Fix cleanup indexes --------- Co-authored-by: Izel Levy <[email protected]>
- Loading branch information
1 parent
b42f06c
commit 3410cd3
Showing
7 changed files
with
50 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
TEST_NAMESPACE = "ns" | ||
TEST_CREATE_INDEX_PARAMS = [ | ||
{"spec": {"serverless": {"cloud": "aws", "region": "us-west-2"}}}, | ||
{"spec": {"pod": {"environment": "eu-west1-gcp", "pod_type": "p1.x1"}}}, | ||
] | ||
|
||
|
||
@pytest.fixture(scope="module", params=[None, TEST_NAMESPACE]) | ||
def namespace(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture(scope="module", | ||
params=TEST_CREATE_INDEX_PARAMS, | ||
# The first key in the spec is the index type ("serverless" \ "pod") | ||
ids=[next(iter(_["spec"])) for _ in TEST_CREATE_INDEX_PARAMS]) | ||
def create_index_params(request): | ||
return request.param |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import logging | ||
from datetime import datetime | ||
from typing import List | ||
|
||
from canopy.knowledge_base.knowledge_base import _get_global_client | ||
from canopy.knowledge_base.knowledge_base import _get_global_client, INDEX_NAME_PREFIX | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
TEST_NAMESPACE = "ns" | ||
TEST_CREATE_INDEX_PARAMS = [ | ||
{"spec": {"serverless": {"cloud": "aws", "region": "us-west-2"}}}, | ||
# TODO: Enable this | ||
# {"spec": {"pod": {"environment": "eu-west1-gcp", "pod_type": "p1.x1"}}}, | ||
] | ||
|
||
|
||
def create_index_name(testrun_uid: str, prefix: str) -> str: | ||
today = datetime.today().strftime("%Y-%m-%d") | ||
return f"{prefix}-{testrun_uid[-6:]}-{today}" | ||
return f"{testrun_uid[-6:]}-{prefix}-{today}" | ||
|
||
|
||
def create_system_tests_index_name(testrun_uid: str) -> str: | ||
return create_index_name(testrun_uid, "test-kb") | ||
|
||
|
||
def create_e2e_tests_index_name(testrun_uid: str) -> str: | ||
return create_index_name(testrun_uid, "test-app") | ||
def create_e2e_tests_index_name(testrun_uid: str, index_type: str) -> str: | ||
return create_index_name(testrun_uid, f"test-app-{index_type}") | ||
|
||
|
||
def get_related_indexes(indexes: List[str], testrun_uid: str) -> List[str]: | ||
return [ | ||
index for index in indexes | ||
if index.startswith(f"{INDEX_NAME_PREFIX}{testrun_uid[-6:]}") | ||
] | ||
|
||
|
||
def cleanup_indexes(testrun_uid: str): | ||
client = _get_global_client() | ||
e2e_index_name = create_e2e_tests_index_name(testrun_uid) | ||
system_index_name = create_system_tests_index_name(testrun_uid) | ||
index_names = (system_index_name, e2e_index_name) | ||
current_indexes = client.list_indexes().names() | ||
index_names = get_related_indexes(current_indexes, testrun_uid) | ||
logger.info(f"Preparing to cleanup indexes: {index_names}") | ||
current_indexes = client.list_indexes() | ||
for index_name in index_names: | ||
if index_name in current_indexes: | ||
logger.info(f"Deleting index '{index_name}'...") | ||
client.delete_index(index_name) | ||
logger.info(f"Index '{index_name}' deleted.") | ||
else: | ||
logger.info(f"Index '{index_name}' does not exist.") | ||
logger.info(f"Deleting index '{index_name}'...") | ||
client.delete_index(index_name) | ||
logger.info(f"Index '{index_name}' deleted.") |