Skip to content

Commit

Permalink
test: add test cases for code change (#32289)
Browse files Browse the repository at this point in the history
issue: #31368

Signed-off-by: binbin lv <[email protected]>
  • Loading branch information
binbinlv authored Apr 29, 2024
1 parent 4e01591 commit 083bd38
Show file tree
Hide file tree
Showing 5 changed files with 618 additions and 155 deletions.
213 changes: 213 additions & 0 deletions tests/python_client/milvus_client/test_milvus_client_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,216 @@ def test_milvus_client_query_limit(self):
"with_vec": True,
"primary_field": default_primary_key_field_name[:limit]})[0]
client_w.drop_collection(client, collection_name)


class TestMilvusClientGetInvalid(TestcaseBase):
""" Test case of search interface """

"""
******************************************************************
# The following are invalid base cases
******************************************************************
"""

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("name",
["12-s", "12 s", "(mn)", "中文", "%$#", "".join("a" for i in range(ct.max_name_length + 1))])
def test_milvus_client_get_invalid_collection_name(self, name):
"""
target: test get interface invalid cases
method: invalid collection name
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, consistency_level="Strong")
# 2. insert
default_nb = 1000
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: i, default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [i for i in range(default_nb)]
# 3. get first primary key
error = {ct.err_code: 1100, ct.err_msg: f"Invalid collection name"}
client_w.get(client, name, ids=pks[0:1],
check_task=CheckTasks.err_res, check_items=error)
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L2)
def test_milvus_client_get_not_exist_collection_name(self):
"""
target: test get interface invalid cases
method: invalid collection name
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, consistency_level="Strong")
# 2. insert
default_nb = 1000
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: i, default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [i for i in range(default_nb)]
# 3. get first primary key
name = "invalid"
error = {ct.err_code: 100, ct.err_msg: f"can't find collection[database=default][collection={name}]"}
client_w.get(client, name, ids=pks[0:1],
check_task=CheckTasks.err_res, check_items=error)
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("invalid_ids",["中文", "%$#"])
def test_milvus_client_get_invalid_ids(self, invalid_ids):
"""
target: test get interface invalid cases
method: invalid collection name
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, consistency_level="Strong")
# 2. insert
default_nb = 1000
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: i, default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
# 3. get first primary key
error = {ct.err_code: 1100, ct.err_msg: f"cannot parse expression"}
client_w.get(client, collection_name, ids=invalid_ids,
check_task=CheckTasks.err_res, check_items=error)
client_w.drop_collection(client, collection_name)


class TestMilvusClientGetValid(TestcaseBase):
""" Test case of search interface """

@pytest.fixture(scope="function", params=[False, True])
def auto_id(self, request):
yield request.param

@pytest.fixture(scope="function", params=["COSINE", "L2"])
def metric_type(self, request):
yield request.param

"""
******************************************************************
# The following are valid base cases
******************************************************************
"""
@pytest.mark.tags(CaseLabel.L1)
def test_milvus_client_get_normal(self):
"""
target: test get interface
method: create connection, collection, insert delete, and search
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, consistency_level="Strong")
# 2. insert
default_nb = 1000
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: i, default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [i for i in range(default_nb)]
# 3. get first primary key
first_pk_data = client_w.get(client, collection_name, ids=pks[0:1])[0]
assert len(first_pk_data) == len(pks[0:1])
first_pk_data_1 = client_w.get(client, collection_name, ids=0)[0]
assert first_pk_data == first_pk_data_1
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L2)
def test_milvus_client_get_output_fields(self):
"""
target: test get interface with output fields
method: create connection, collection, insert delete, and search
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, consistency_level="Strong")
# 2. insert
default_nb = 1000
rng = np.random.default_rng(seed=19530)
rows = [{default_primary_key_field_name: i, default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [i for i in range(default_nb)]
# 3. get first primary key
output_fields_array = [default_primary_key_field_name, default_vector_field_name,
default_float_field_name, default_string_field_name]
first_pk_data = client_w.get(client, collection_name, ids=pks[0:1], output_fields=output_fields_array)[0]
assert len(first_pk_data) == len(pks[0:1])
assert len(first_pk_data[0]) == len(output_fields_array)
first_pk_data_1 = client_w.get(client, collection_name, ids=0, output_fields=output_fields_array)[0]
assert first_pk_data == first_pk_data_1
assert len(first_pk_data_1[0]) == len(output_fields_array)
client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.skip(reason="pymilvus issue 2056")
def test_milvus_client_get_normal_string(self):
"""
target: test get interface for string field
method: create connection, collection, insert delete, and search
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, id_type="string", max_length=ct.default_length)
# 2. insert
rng = np.random.default_rng(seed=19530)
rows = [
{default_primary_key_field_name: str(i), default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [str(i) for i in range(default_nb)]
# 3. get first primary key
first_pk_data = client_w.get(client, collection_name, ids=pks[0:1])[0]
assert len(first_pk_data) == len(pks[0:1])
first_pk_data_1 = client_w.get(client, collection_name, ids="0")[0]
assert first_pk_data == first_pk_data_1

client_w.drop_collection(client, collection_name)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.skip(reason="pymilvus issue 2056")
def test_milvus_client_get_normal_string_output_fields(self):
"""
target: test get interface for string field
method: create connection, collection, insert delete, and search
expected: search/query successfully without deleted data
"""
client = self._connect(enable_milvus_client_api=True)
collection_name = cf.gen_unique_str(prefix)
# 1. create collection
client_w.create_collection(client, collection_name, default_dim, id_type="string", max_length=ct.default_length)
# 2. insert
rng = np.random.default_rng(seed=19530)
rows = [
{default_primary_key_field_name: str(i), default_vector_field_name: list(rng.random((1, default_dim))[0]),
default_float_field_name: i * 1.0, default_string_field_name: str(i)} for i in range(default_nb)]
client_w.insert(client, collection_name, rows)[0]
pks = [str(i) for i in range(default_nb)]
# 3. get first primary key
output_fields_array = [default_primary_key_field_name, default_vector_field_name,
default_float_field_name, default_string_field_name]
first_pk_data = client_w.get(client, collection_name, ids=pks[0:1], output_fields=output_fields_array)[0]
assert len(first_pk_data) == len(pks[0:1])
assert len(first_pk_data[0]) == len(output_fields_array)
first_pk_data_1 = client_w.get(client, collection_name, ids="0", output_fields=output_fields_array)[0]
assert first_pk_data == first_pk_data_1
assert len(first_pk_data_1[0]) == len(output_fields_array)
client_w.drop_collection(client, collection_name)
2 changes: 1 addition & 1 deletion tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4489,7 +4489,7 @@ def test_create_collection_multiple_vectors_invalid_all_vector_field_name(self,
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #29796")
@pytest.mark.skip(reason="issue #29796")
def test_create_collection_multiple_vectors_invalid_dim(self, get_invalid_dim):
"""
target: test create collection with multiple vector fields
Expand Down
2 changes: 1 addition & 1 deletion tests/python_client/testcases/test_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def get_non_number_replicas(self, request):
yield request.param

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.xfail(reason="issue #21618")
@pytest.mark.skip(reason="issue #21618")
def test_load_partition_replica_non_number(self, get_non_number_replicas):
"""
target: test load partition with non-number replicas
Expand Down
10 changes: 5 additions & 5 deletions tests/python_client/testcases/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ def test_query_output_one_field(self, enable_dynamic_field):
assert set(res[0].keys()) == {ct.default_int64_field_name, ct.default_float_field_name}

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue 30437")
@pytest.mark.skip(reason="issue 30437")
def test_query_output_all_fields(self, enable_dynamic_field, random_primary_key):
"""
target: test query with none output field
Expand Down Expand Up @@ -1505,7 +1505,7 @@ def test_query_output_not_existed_field(self):
check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.xfail(reason="exception not MilvusException")
@pytest.mark.skip(reason="exception not MilvusException")
def test_query_invalid_output_fields(self):
"""
target: test query with invalid output fields
Expand All @@ -1520,7 +1520,7 @@ def test_query_invalid_output_fields(self):
check_items=error)

@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.xfail(reason="issue 24637")
@pytest.mark.skip(reason="issue 24637")
def test_query_output_fields_simple_wildcard(self):
"""
target: test query output_fields with simple wildcard (* and %)
Expand All @@ -1539,7 +1539,7 @@ def test_query_output_fields_simple_wildcard(self):
check_items={exp_res: res3, "with_vec": True})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue 24637")
@pytest.mark.skip(reason="issue 24637")
def test_query_output_fields_part_scale_wildcard(self):
"""
target: test query output_fields with part wildcard
Expand Down Expand Up @@ -2679,7 +2679,7 @@ def test_query_compare_invalid_fields(self):
f"error: comparisons between VarChar and Int64 are not supported: invalid parameter"})

@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue 24637")
@pytest.mark.skip(reason="issue 24637")
def test_query_after_insert_multi_threading(self):
"""
target: test data consistency after multi threading insert
Expand Down
Loading

0 comments on commit 083bd38

Please sign in to comment.