未验证 提交 bc3e0619 编写于 作者: Y yanliang567 提交者: GitHub

[skip ci] update partition tests (#5656)

Signed-off-by: Nyanliang567 <yanliang.qiao@zilliz.com>
上级 79e43ddb
......@@ -98,8 +98,11 @@ class TestcaseBase(Base):
def _connect(self):
""" Add an connection and create the connect """
self.connection_wrap.add_connection(default={"host": param_info.param_host, "port": param_info.param_port})
res, _ = self.connection_wrap.connect(alias='default')
res, is_succ = self.connection_wrap.connect(alias='default')
if not is_succ:
raise res
return res
'''
def _collection(self, **kwargs):
""" Init a collection and return the object of collection """
......@@ -121,7 +124,7 @@ class TestcaseBase(Base):
check_task=check_task, **kwargs)
return collection_w
def init_partition_wrap(self, collection_wrap, name=None, description=None,
def init_partition_wrap(self, collection_wrap=None, name=None, description=None,
check_task=None, check_items=None, **kwargs):
name = cf.gen_unique_str("partition_") if name is None else name
description = cf.gen_unique_str("partition_des_") if description is None else description
......
......@@ -30,10 +30,10 @@ class ApiConnectionsWrapper:
check_result = ResponseChecker(res, func_name, check_res, check_params, check, alias=alias).run()
return res, check_result
def connect(self, alias=DefaultConfig.DEFAULT_USING, check_res=None, check_params=None, **kwargs):
def connect(self, alias=DefaultConfig.DEFAULT_USING, check_task=None, check_items=None, **kwargs):
func_name = sys._getframe().f_code.co_name
res, check = api_request([self.connection.connect, alias], **kwargs)
check_result = ResponseChecker(res, func_name, check_res, check_params, check, alias=alias, **kwargs).run()
res, succ = api_request([self.connection.connect, alias], **kwargs)
check_result = ResponseChecker(res, func_name, check_task, check_items, succ, alias=alias, **kwargs).run()
return res, check_result
def get_connection(self, alias=DefaultConfig.DEFAULT_USING, check_res=None, check_params=None):
......
......@@ -52,9 +52,9 @@ class ResponseChecker:
assert actual is False
assert len(error_dict) > 0
if isinstance(res, Error):
err_code = error_dict["err_code"]
assert res.code == err_code or ErrorMessage[err_code] in res.message
# assert res.code == error_dict["err_code"] or error_dict["err_msg"] in res.message
# err_code = error_dict["err_code"]
# assert res.code == err_code or ErrorMessage[err_code] in res.message
assert res.code == error_dict["err_code"] or error_dict["err_msg"] in res.message
else:
log.error("[CheckFunc] Response of API is not an error: %s" % str(res))
assert False
......@@ -83,9 +83,13 @@ class ResponseChecker:
log.warning("The function name is {} rather than {}".format(func_name, exp_func_name))
if not isinstance(collection, Collection):
raise Exception("The result to check isn't collection type object")
assert collection.name == check_items["name"]
assert collection.description == check_items["schema"].description
assert collection.schema == check_items["schema"]
if len(check_items) == 0:
raise Exception("No expect values found in the check task")
if check_items.get("name", None):
assert collection.name == check_items["name"]
if check_items.get("schema", None):
assert collection.description == check_items["schema"].description
assert collection.schema == check_items["schema"]
return True
@staticmethod
......@@ -97,13 +101,13 @@ class ResponseChecker:
raise Exception("The result to check isn't partition type object")
if len(check_items) == 0:
raise Exception("No expect values found in the check task")
if check_items["name"]:
if check_items.get("name", None):
assert partition.name == check_items["name"]
if check_items["description"]:
if check_items.get("description", None):
assert partition.description == check_items["description"]
if check_items["is_empty"]:
if check_items.get("is_empty", None):
assert partition.is_empty == check_items["is_empty"]
if check_items["num_entities"]:
if check_items.get("num_entities", None):
assert partition.num_entities == check_items["num_entities"]
return True
......@@ -22,6 +22,10 @@ def gen_unique_str(str_value=None):
return "test_" + prefix if str_value is None else str_value + "_" + prefix
def gen_str_by_length(length=8):
return "".join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
def gen_int64_field(name=ct.default_int64_field_name, is_primary=False, description=ct.default_desc):
int64_field = FieldSchema(name=name, dtype=DataType.INT64, description=description, is_primary=is_primary)
return int64_field
......
......@@ -226,9 +226,9 @@ class TestConnectionOperation(TestcaseBase):
"""
# error
self.connection_wrap.add_connection(default={"host": 'host', "port": port})
res = self.connection_wrap.connect(alias="default", host=host, port=port, check_res='')
res = self.connection_wrap.connect(alias="default", host=host, port=port, check_task='')
log.info(res[0])
res = self.connection_wrap.connect(alias="default", host=host, port=port, check_res='')
res = self.connection_wrap.connect(alias="default", host=host, port=port, check_task='')
log.info(res[0])
@pytest.mark.tags(CaseLabel.L1)
......@@ -252,7 +252,7 @@ class TestConnectionOperation(TestcaseBase):
expected: assert res is wrong
"""
self.connection_wrap.get_connection(alias='default', check_res=CheckTasks.false)
res = self.connection_wrap.connect(alias="default", host='host', port=port, check_res='')
res = self.connection_wrap.connect(alias="default", host='host', port=port, check_task='')
assert res[0].args[0] == "Fail connecting to server on host:19530. Timeout"
@pytest.mark.tags(CaseLabel.L1)
......
......@@ -37,6 +37,7 @@ class TestPartitionParams(TestcaseBase):
assert collection_w.has_partition(partition_name)[0]
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5375")
@pytest.mark.parametrize("partition_name", [""])
def test_partition_empty_name(self, partition_name):
"""
......@@ -50,7 +51,7 @@ class TestPartitionParams(TestcaseBase):
# create partition
self.partition_wrap.init_partition(collection_w.collection, partition_name,
check_task=CheckTasks.err_res,
check_items={"err_code": 1, "err_msg": "Partition tag should not be empty"})
check_items={"err_code": 1, "err_msg": "Partition name should not be empty"})
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("partition_name, description", [(cf.gen_unique_str(prefix), "")])
......@@ -74,6 +75,27 @@ class TestPartitionParams(TestcaseBase):
# check that the partition has been created
assert collection_w.has_partition(partition_name)[0]
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("partition_name, description",
[(cf.gen_str_by_length(255), cf.gen_str_by_length(2048))])
def test_partition_max_description_length(self, partition_name, description):
"""
target: verify create a partition with 255 length name and 1024 length description
method: 1. create a partition with 255 length name and 1024 length description
expected: 1. create successfully
"""
# create collection
collection_w = self.init_collection_wrap()
# init partition
self.init_partition_wrap(collection_w, partition_name,
description=description,
check_task=CheckTasks.check_partition_property,
check_items={"name": partition_name, "description": description,
"is_empty": True}
)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("collection_name, partition_name, description",
[(cf.gen_unique_str(), cf.gen_unique_str(prefix), cf.gen_unique_str())])
......@@ -116,10 +138,8 @@ class TestPartitionParams(TestcaseBase):
"is_empty": True, "num_entities": 0}
)
assert collection_w.has_partition(partition_name)[0]
assert collection_w.description == description
@pytest.mark.tags(CaseLabel.L1)
# @pytest.mark.xfail(reason="issue #5373")
def test_partition_default_name(self):
"""
target: verify create a partition with default name
......@@ -140,6 +160,23 @@ class TestPartitionParams(TestcaseBase):
partition_w = self.init_partition_wrap(collection_w, ct.default_partition_name)
assert collection.name == partition_w.name
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("partition_name", [cf.gen_str_by_length(256)])
def test_partition_maxlength_name(self, partition_name):
"""
target: verify create a partition with maxlength(256) name
method: 1. create a partition with max length names
expected: 1. raise exception
"""
# create collection
collection_w = self.init_collection_wrap()
# create partition
self.partition_wrap.init_partition(collection_w.collection, partition_name,
check_task=CheckTasks.err_res,
check_items={"err_code": 1, 'err_msg': "is illegal"}
)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("partition_name", ct.get_invalid_strs)
def test_partition_invalid_name(self, partition_name):
......@@ -149,10 +186,10 @@ class TestPartitionParams(TestcaseBase):
expected: 1. raise exception
"""
# create collection
self.init_collection_wrap()
collection_w = self.init_collection_wrap()
# create partition
self.partition_wrap.init_partition(self.collection_wrap.collection, partition_name,
self.partition_wrap.init_partition(collection_w.collection, partition_name,
check_task=CheckTasks.err_res,
check_items={"err_code": 1, 'err_msg': "is illegal"}
)
......@@ -359,24 +396,23 @@ class TestPartitionOperations(TestcaseBase):
for _ in range(ct.max_partition_num // threads_n):
name = cf.gen_unique_str(prefix)
par_wrap = ApiPartitionWrapper()
par_wrap.init_partition(collection, name)
par_wrap.init_partition(collection, name, check_task="check_nothing")
m_collection = self.init_collection_wrap()
collection_w = self.init_collection_wrap()
for _ in range(threads_num):
t = threading.Thread(target=create_partition, args=(m_collection, threads_num))
t = threading.Thread(target=create_partition, args=(collection_w.collection, threads_num))
threads.append(t)
t.start()
for t in threads:
t.join()
p_name = cf.gen_unique_str()
self.partition_wrap.init_partition(
m_collection, p_name,
collection_w.collection, p_name,
check_task=CheckTasks.err_res,
check_items={"err_code": 1,
"err_msg": "maximum partition's number should be limit to 4096"})
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5302")
@pytest.mark.parametrize("partition_name", [ct.default_partition_name])
def test_partition_drop_default_partition(self, partition_name):
"""
......@@ -387,12 +423,14 @@ class TestPartitionOperations(TestcaseBase):
# create collection
collection_w = self.init_collection_wrap()
# init partition
partition_w = collection_w.partition(ct.default_partition_name)
# get the default partition
default_partition, _ = collection_w.partition(ct.default_partition_name)
partition_w = self.init_partition_wrap(collection_w, ct.default_partition_name)
assert default_partition.name == partition_w.name
# verify that drop partition with error
partition_w.drop(check_task=CheckTasks.err_res,
check_items={"err_code": 1, "err_msg": "not"})
check_items={"err_code": 1, "err_msg": "default partition cannot be deleted"})
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("partition_name", [cf.gen_unique_str(prefix)])
......@@ -413,7 +451,7 @@ class TestPartitionOperations(TestcaseBase):
# drop partition
partition_w.drop()
assert not collection_w.has_partition(partition_name)
assert not collection_w.has_partition(partition_name)[0]
# verify that drop the partition again with exception
partition_w.drop(check_task=CheckTasks.err_res,
......@@ -488,14 +526,14 @@ class TestPartitionOperations(TestcaseBase):
expected: drop successfully
"""
# create collection
collection_w = self._collection()
collection_w = self.init_collection_wrap()
# create partition
partition_w = self.init_partition_wrap(collection_w, partition_name)
assert collection_w.has_partition(partition_name)
assert collection_w.has_partition(partition_name)[0]
# insert data to partition
self.partition_wrap.insert(data)
partition_w.insert(data)
# create index of collection
collection_w.create_index(ct.default_float_vec_field_name, index_param)
......@@ -631,6 +669,7 @@ class TestPartitionOperations(TestcaseBase):
# insert data to partition
partition_w.insert(data)
# TODO: need a flush here
assert partition_w.num_entities == len(data)
@pytest.mark.tags(CaseLabel.L1)
......@@ -696,10 +735,8 @@ class TestPartitionOperations(TestcaseBase):
assert partition_w.num_entities == max_size
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("dim, expected_err",
[(ct.default_dim - 1, "error"), (ct.default_dim + 1, "error")])
@pytest.mark.parametrize("partition_name", [cf.gen_unique_str(prefix)])
def test_partition_insert_mismatched_dimensions(self, dim, expected_err, partition_name):
@pytest.mark.parametrize("dim", [ct.default_dim - 1, ct.default_dim + 1])
def test_partition_insert_mismatched_dimensions(self, dim):
"""
target: verify insert maximum size data(256M?) a time
method: 1.create a collection with default dim
......@@ -707,12 +744,12 @@ class TestPartitionOperations(TestcaseBase):
expected: raise exception
"""
# create partition
partition_w = self.init_partition_wrap(partition_name)
partition_w = self.init_partition_wrap()
data = cf.gen_default_list_data(nb=10, dim=dim)
# insert data to partition
partition_w.insert(data, check_task=CheckTasks.err_res,
check_items={"err_code": 1, "err_msg": "blabla"})
check_items={"err_code": 1, "err_msg": "Field type doesn't match"})
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("sync", [True, False])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册