Skip to content

Commit

Permalink
test: Add index names tests for mulitple vectors support (#33250)
Browse files Browse the repository at this point in the history
Related issue: #32653
1. Update index name tests
2. remove some time.sleep

---------

Signed-off-by: yanliang567 <yanliang.qiao@zilliz.com>
  • Loading branch information
yanliang567 committed May 23, 2024
1 parent 155cb40 commit 00cd88e
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 366 deletions.
2 changes: 0 additions & 2 deletions tests/python_client/base/collection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def hybrid_search(self, reqs, rerank, limit, partition_names=None, output_fields
@trace()
def query(self, expr, output_fields=None, partition_names=None, timeout=None, check_task=None, check_items=None,
**kwargs):
# time.sleep(5)
timeout = TIMEOUT if timeout is None else timeout

func_name = sys._getframe().f_code.co_name
Expand All @@ -240,7 +239,6 @@ def query(self, expr, output_fields=None, partition_names=None, timeout=None, ch
@trace()
def query_iterator(self, batch_size=1000, limit=-1, expr=None, output_fields=None, partition_names=None, timeout=None,
check_task=None, check_items=None, **kwargs):
# time.sleep(5)
timeout = TIMEOUT if timeout is None else timeout

func_name = sys._getframe().f_code.co_name
Expand Down
59 changes: 24 additions & 35 deletions tests/python_client/testcases/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ def test_collection_invalid_name(self, name):
expected: raise exception
"""
self._connect()
error = {ct.err_code: 1, ct.err_msg: "Invalid collection name: {}".format(name)}
if name is not None and name.strip() == "":
error = {ct.err_code: 1, ct.err_msg: "collection name should not be empty"}
error = {ct.err_code: 999, ct.err_msg: f"Invalid collection name: {name}"}
if name in [None, ""]:
error = {ct.err_code: 999, ct.err_msg: f"`collection_name` value {name} is illegal"}
if name in [" "]:
error = {ct.err_code: 999, ct.err_msg: f"collection name should not be empty"}
self.collection_wrap.init_collection(name, schema=default_schema, check_task=CheckTasks.err_res,
check_items=error)

Expand Down Expand Up @@ -161,8 +163,8 @@ def test_collection_dup_name_new_schema(self):
check_items={exp_name: c_name, exp_schema: default_schema})
fields = [cf.gen_int64_field(is_primary=True)]
schema = cf.gen_collection_schema(fields=fields)
error = {ct.err_code: 0, ct.err_msg: "The collection already exist, but the schema is not the same as the "
"schema passed in."}
error = {ct.err_code: 999, ct.err_msg: "The collection already exist, but the schema is not the same as the "
"schema passed in."}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
Expand Down Expand Up @@ -382,7 +384,7 @@ def test_collection_without_vectors(self):
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_collection_schema([cf.gen_int64_field(is_primary=True)])
error = {ct.err_code: 0, ct.err_msg: "No vector field is found."}
error = {ct.err_code: 999, ct.err_msg: "No vector field is found."}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L1)
Expand Down Expand Up @@ -428,7 +430,7 @@ def test_collection_invalid_is_primary(self, is_primary):
check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("primary_field", ["12-s", "12 s", "(mn)", "中文", "%$#", "a".join("a" for i in range(256))])
@pytest.mark.parametrize("primary_field", ["12-s", "non_existing", "(mn)", "中文", None])
def test_collection_invalid_primary_field(self, primary_field):
"""
target: test collection with invalid primary_field
Expand All @@ -437,12 +439,12 @@ def test_collection_invalid_primary_field(self, primary_field):
"""
self._connect()
fields = [cf.gen_int64_field(), cf.gen_float_vec_field()]
error = {ct.err_code: 1, ct.err_msg: "Schema must have a primary key field."}
error = {ct.err_code: 999, ct.err_msg: "Schema must have a primary key field"}
self.collection_schema_wrap.init_collection_schema(fields=fields, primary_field=primary_field,
check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("primary_field", [[], 1, [1, "2", 3], (1,), {1: 1}, None])
@pytest.mark.parametrize("primary_field", [[], 1, [1, "2", 3], (1,), {1: 1}])
def test_collection_non_string_primary_field(self, primary_field):
"""
target: test collection with non-string primary_field
Expand All @@ -451,25 +453,10 @@ def test_collection_non_string_primary_field(self, primary_field):
"""
self._connect()
fields = [cf.gen_int64_field(), cf.gen_float_vec_field()]
error = {ct.err_code: 1, ct.err_msg: "Param primary_field must be str type."}
error = {ct.err_code: 999, ct.err_msg: "Param primary_field must be int or str type"}
self.collection_schema_wrap.init_collection_schema(fields, primary_field=primary_field,
check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
def test_collection_not_existed_primary_field(self):
"""
target: test collection with not exist primary field
method: specify not existed field as primary_field
expected: raise exception
"""
self._connect()
fake_field = cf.gen_unique_str()
fields = [cf.gen_int64_field(), cf.gen_float_vec_field()]
error = {ct.err_code: 1, ct.err_msg: "Schema must have a primary key field."}

self.collection_schema_wrap.init_collection_schema(fields, primary_field=fake_field,
check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L0)
def test_collection_primary_in_schema(self):
"""
Expand Down Expand Up @@ -506,7 +493,7 @@ def test_collection_unsupported_primary_field(self, get_unsupported_primary_fiel
self._connect()
field = get_unsupported_primary_field
vec_field = cf.gen_float_vec_field(name="vec")
error = {ct.err_code: 1, ct.err_msg: "Primary key type must be DataType.INT64 or DataType.VARCHAR."}
error = {ct.err_code: 999, ct.err_msg: "Primary key type must be DataType.INT64 or DataType.VARCHAR."}
self.collection_schema_wrap.init_collection_schema(fields=[field, vec_field], primary_field=field.name,
check_task=CheckTasks.err_res, check_items=error)

Expand All @@ -520,7 +507,7 @@ def test_collection_multi_primary_fields(self):
self._connect()
int_field_one = cf.gen_int64_field(is_primary=True)
int_field_two = cf.gen_int64_field(name="int2", is_primary=True)
error = {ct.err_code: 0, ct.err_msg: "Expected only one primary key field"}
error = {ct.err_code: 999, ct.err_msg: "Expected only one primary key field"}
self.collection_schema_wrap.init_collection_schema(
fields=[int_field_one, int_field_two, cf.gen_float_vec_field()],
check_task=CheckTasks.err_res, check_items=error)
Expand All @@ -536,7 +523,7 @@ def test_collection_primary_inconsistent(self):
int_field_one = cf.gen_int64_field(is_primary=True)
int_field_two = cf.gen_int64_field(name="int2")
fields = [int_field_one, int_field_two, cf.gen_float_vec_field()]
error = {ct.err_code: 1, ct.err_msg: "Expected only one primary key field"}
error = {ct.err_code: 999, ct.err_msg: "Expected only one primary key field"}
self.collection_schema_wrap.init_collection_schema(fields, primary_field=int_field_two.name,
check_task=CheckTasks.err_res, check_items=error)

Expand Down Expand Up @@ -597,7 +584,7 @@ def test_collection_auto_id_non_primary_field(self):
expected: raise exception
"""
self._connect()
error = {ct.err_code: 0, ct.err_msg: "auto_id can only be specified on the primary key field"}
error = {ct.err_code: 999, ct.err_msg: "auto_id can only be specified on the primary key field"}
self.field_schema_wrap.init_field_schema(name=ct.default_int64_field_name, dtype=DataType.INT64, auto_id=True,
check_task=CheckTasks.err_res, check_items=error)

Expand All @@ -616,19 +603,21 @@ def test_collection_auto_id_false_non_primary(self):
assert not schema.auto_id

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.xfail(reason="issue 24578")
def test_collection_auto_id_inconsistent(self):
@pytest.mark.xfail(reason="pymilvus issue, should use fieldschema as top priority")
@pytest.mark.parametrize("auto_id", [True, False])
def test_collection_auto_id_inconsistent(self, auto_id):
"""
target: test collection auto_id with both collection schema and field schema
method: 1.set primary field auto_id=True in field schema 2.set auto_id=False in collection schema
expected: raise exception
"""
self._connect()
int_field = cf.gen_int64_field(is_primary=True, auto_id=True)
int_field = cf.gen_int64_field(is_primary=True, auto_id=auto_id)
vec_field = cf.gen_float_vec_field(name='vec')
schema, _ = self.collection_schema_wrap.init_collection_schema([int_field, vec_field], auto_id=not auto_id)
collection_w = self.collection_wrap.init_collection(cf.gen_unique_str(prefix), schema=schema)[0]

schema, _ = self.collection_schema_wrap.init_collection_schema([int_field, vec_field], auto_id=False)
assert schema.auto_id
assert collection_w.schema.auto_id is auto_id

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("auto_id", [True, False])
Expand Down Expand Up @@ -718,7 +707,7 @@ def test_collection_vector_invalid_dim(self, get_invalid_dim):
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)

@pytest.mark.tags(CaseLabel.L2)
@pytest.mark.parametrize("dim", [-1, 0, 32769])
@pytest.mark.parametrize("dim", [ct.min_dim-1, ct.max_dim+1])
def test_collection_vector_out_bounds_dim(self, dim):
"""
target: test collection with out of bounds dim
Expand Down
Loading

0 comments on commit 00cd88e

Please sign in to comment.