From a9cbf433535c7f81d66ea8c4a5e12c2d6c7f5cec Mon Sep 17 00:00:00 2001 From: nico <109071306+NicoYuan1986@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:59:31 +0800 Subject: [PATCH] Add cases about offset and alias (#26067) Signed-off-by: nico --- tests/python_client/requirements.txt | 2 +- .../testcases/test_collection.py | 5 ++-- tests/python_client/testcases/test_search.py | 20 ++++++++++++++ tests/python_client/testcases/test_utility.py | 27 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tests/python_client/requirements.txt b/tests/python_client/requirements.txt index c14206f0f3..f23cdde3cb 100644 --- a/tests/python_client/requirements.txt +++ b/tests/python_client/requirements.txt @@ -12,7 +12,7 @@ allure-pytest==2.7.0 pytest-print==0.2.1 pytest-level==0.1.1 pytest-xdist==2.5.0 -pymilvus==2.4.0.dev109 +pymilvus==2.4.0.dev115 pytest-rerunfailures==9.1.1 git+https://github.com/Projectplace/pytest-tags ndg-httpsclient diff --git a/tests/python_client/testcases/test_collection.py b/tests/python_client/testcases/test_collection.py index b973466630..fcae573a76 100644 --- a/tests/python_client/testcases/test_collection.py +++ b/tests/python_client/testcases/test_collection.py @@ -3805,7 +3805,8 @@ class TestCollectionString(TestcaseBase): schema = self.collection_schema_wrap.init_collection_schema(fields=fields)[0] self.init_collection_wrap(schema=schema, check_task=CheckTasks.check_collection_property, check_items={"schema": schema, "primary": ct.default_string_field_name}) - + + class TestCollectionJSON(TestcaseBase): """ ****************************************************************** @@ -3884,5 +3885,3 @@ class TestCollectionJSON(TestcaseBase): self.collection_wrap.init_collection(name=c_name, schema=schema, check_task=CheckTasks.check_collection_property, check_items={exp_name: c_name, exp_schema: schema}) - - diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index f992975923..7aff42b33c 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -5425,6 +5425,26 @@ class TestSearchPagination(TestcaseBase): # assert sorted(search_res[0].distances, key=numpy.float32) == sorted(res_distance, key=numpy.float32) assert set(search_res[0].ids) == set(res[0].ids[offset:]) + @pytest.mark.tags(CaseLabel.L2) + @pytest.mark.parametrize("offset", [100, default_nb // 2]) + def test_search_offset_different_position(self, offset): + """ + target: test search pagination with offset in different position + method: create connection, collection, insert entities and search with offset + expected: search successfully + """ + # 1. initialize + collection_w = self.init_collection_general(prefix, True)[0] + # 2. search with offset in params + search_params = {"metric_type": "COSINE", "params": {"nprobe": 10}, "offset": offset} + res1 = collection_w.search(vectors[:default_nq], default_search_field, + search_params, default_limit)[0] + + # 3. search with offset outside params + res2 = collection_w.search(vectors[:default_nq], default_search_field, default_search_params, + default_limit, offset=offset)[0] + assert res1[0].ids == res2[0].ids + class TestSearchPaginationInvalid(TestcaseBase): """ Test case of search pagination """ diff --git a/tests/python_client/testcases/test_utility.py b/tests/python_client/testcases/test_utility.py index 4727bc61cd..e128030280 100644 --- a/tests/python_client/testcases/test_utility.py +++ b/tests/python_client/testcases/test_utility.py @@ -1647,6 +1647,33 @@ class TestUtilityBase(TestcaseBase): assert collection_alias[0] in collections assert old_collection_name not in collections + @pytest.mark.tags(CaseLabel.L2) + def test_create_alias_using_dropped_collection_name(self): + """ + target: test create alias using a dropped collection name + method: create 2 collections and drop one collection + expected: raise no exception + """ + # 1. create 2 collections + a_name = cf.gen_unique_str("aa") + b_name = cf.gen_unique_str("bb") + self.init_collection_wrap(name=a_name, schema=default_schema, + check_task=CheckTasks.check_collection_property, + check_items={exp_name: a_name, exp_schema: default_schema}) + self.init_collection_wrap(name=b_name, schema=default_schema, + check_task=CheckTasks.check_collection_property, + check_items={exp_name: b_name, exp_schema: default_schema}) + + # 2. drop collection a + self.utility_wrap.drop_collection(a_name) + assert self.utility_wrap.has_collection(a_name)[0] is False + assert len(self.utility_wrap.list_aliases(b_name)[0]) == 0 + + # 3. create alias with the name of collection a + self.utility_wrap.create_alias(b_name, a_name) + b_alias, _ = self.utility_wrap.list_aliases(b_name) + assert a_name in b_alias + class TestUtilityAdvanced(TestcaseBase): """ Test case of index interface """