未验证 提交 e2dcbf53 编写于 作者: 紫晴 提交者: GitHub

[skip ci] Verify connection interface issues (#6095)

Signed-off-by: Nwangting0128 <ting.wang@zilliz.com>
上级 fffdb348
......@@ -63,8 +63,14 @@ class Base:
try:
""" Drop collection before disconnect """
if self.collection_wrap is not None and self.collection_wrap.collection is not None:
self.collection_wrap.drop()
# if self.collection_wrap is not None and self.collection_wrap.collection is not None:
# self.collection_wrap.drop()
if self.collection_wrap is not None:
collection_list = self.utility_wrap.list_collections()[0]
for i in collection_list:
collection_wrap = ApiCollectionWrapper()
collection_wrap.init_collection(name=i)
collection_wrap.drop()
except Exception as e:
pass
......@@ -115,21 +121,17 @@ 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, is_succ = self.connection_wrap.connect(alias='default')
if not is_succ:
raise res
log.info("_connect: Connected")
res, is_succ = self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=param_info.param_host,
port=param_info.param_port)
return res
def init_collection_wrap(self, name=None, schema=None, check_task=None, **kwargs):
def init_collection_wrap(self, name=None, schema=None, check_task=None, check_items=None, **kwargs):
name = cf.gen_unique_str('coll_') if name is None else name
schema = cf.gen_default_collection_schema() if schema is None else schema
if self.connection_wrap.get_connection(alias='default')[0] is None:
if self.connection_wrap.get_connection(alias=DefaultConfig.DEFAULT_USING)[0] is None:
self._connect()
collection_w = ApiCollectionWrapper()
collection_w.init_collection(name=name, schema=schema,
check_task=check_task, **kwargs)
collection_w.init_collection(name=name, schema=schema, check_task=check_task, check_items=check_items, **kwargs)
return collection_w
def init_partition_wrap(self, collection_wrap=None, name=None, description=None,
......
from enum import Enum
from pymilvus_orm.exceptions import ExceptionsMessage
class ErrorCode(Enum):
......@@ -10,12 +11,6 @@ ErrorMessage = {ErrorCode.ErrorOk: "",
ErrorCode.Error: "is illegal"}
class ConnectionErrorMessage:
NoHostPort = "connection configuration must contain 'host' and 'port'"
HostType = "Type of 'host' must be str!"
PortType = "Type of port type must be str or int!"
NotHostPort = "Connection configuration must be contained host and port"
AliasExist = "alias of '%s' already creating connections, but the configure is not the same as passed in."
AliasNotExist = "You need to pass in the configuration of the connection named '%s'"
class ConnectionErrorMessage(ExceptionsMessage):
FailConnect = "Fail connecting to server on %s:%s. Timeout"
ConnectExist = "The connection named %s already creating, but passed parameters don't match the configured parameters"
......@@ -63,6 +63,18 @@ get_invalid_strs = [
"%$#",
"a".join("a" for i in range(256))]
get_not_string = [
[],
{},
None,
(1, ),
1,
1.0,
[1, "2", 3]
]
get_dict_without_host_port = [
{"host": "host"},
{"port": "port"},
......
......@@ -12,7 +12,7 @@ pytest-print==0.2.1
pytest-level==0.1.1
pytest-xdist==2.2.1
pytest-parallel
pymilvus-orm==2.0a1.dev33
pymilvus-orm==2.0a1.dev57
pytest-rerunfailures==9.1.1
git+https://github.com/Projectplace/pytest-tags
ndg-httpsclient
......
import pytest
import os
from pymilvus_orm.default_config import DefaultConfig
from base.client_base import TestcaseBase
from utils.util_log import test_log as log
import common.common_type as ct
......@@ -26,7 +25,7 @@ class TestConnectionParams(TestcaseBase):
# check param of **kwargs
self.connection_wrap.add_connection(_kwargs=data, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: cem.NoHostPort})
check_items={ct.err_code: 0, ct.err_msg: cem.NoHostPort})
# get addr of default alias
self.connection_wrap.get_connection_addr(alias=DefaultConfig.DEFAULT_USING, check_task=ct.CheckTasks.ccr,
......@@ -50,11 +49,10 @@ class TestConnectionParams(TestcaseBase):
# No check for **kwargs
self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, _kwargs=[1, 2],
check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: cem.NotHostPort})
check_items={ct.err_code: 0, ct.err_msg: cem.NoHostPort})
@pytest.mark.xfail(reason="Feature #5725")
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("alias", ct.get_invalid_strs)
@pytest.mark.parametrize("alias", ct.get_not_string)
def test_connection_connect_alias_param_check(self, alias):
"""
target: test connect passes wrong params of alias
......@@ -62,13 +60,12 @@ class TestConnectionParams(TestcaseBase):
expected: assert response is error
"""
# No check for alias
res = self.connection_wrap.connect(alias=alias)
log.info(res[0])
# check for alias
self.connection_wrap.connect(alias=alias, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.AliasType % type(alias)})
@pytest.mark.xfail(reason="Feature #5725")
@pytest.mark.parametrize("alias", ct.get_invalid_strs)
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("alias", ct.get_not_string)
def test_connection_get_alias_param_check(self, alias):
"""
target: test get connection passes wrong params of alias
......@@ -76,13 +73,12 @@ class TestConnectionParams(TestcaseBase):
expected: assert response is error
"""
# not check for alias
res = self.connection_wrap.get_connection(alias=alias)
log.info(res[0])
# check for alias
self.connection_wrap.get_connection(alias=alias, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.AliasType % type(alias)})
@pytest.mark.xfail(reason="Feature #5725")
@pytest.mark.parametrize("alias", ct.get_invalid_strs)
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("alias", ct.get_not_string)
def test_connection_get_addr_alias_param_check(self, alias):
"""
target: test get connection addr passes wrong params of alias
......@@ -90,13 +86,12 @@ class TestConnectionParams(TestcaseBase):
expected: assert response is error
"""
# not check for alias
res = self.connection_wrap.get_connection_addr(alias=alias)
log.info(res[0])
# check for alias
self.connection_wrap.get_connection_addr(alias=alias, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.AliasType % type(alias)})
@pytest.mark.xfail(reason="Feature #5725")
@pytest.mark.parametrize("alias", ct.get_invalid_strs)
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("alias", ct.get_not_string)
def test_connection_remove_alias_param_check(self, alias):
"""
target: test remove connection passes wrong params of alias
......@@ -104,14 +99,13 @@ class TestConnectionParams(TestcaseBase):
expected: assert response is error
"""
# not check for alias
# check for alias
self._connect()
res = self.connection_wrap.remove_connection(alias=alias)
log.info(res[0])
self.connection_wrap.remove_connection(alias=alias, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.AliasType % type(alias)})
@pytest.mark.xfail(reason="Feature #5725")
@pytest.mark.parametrize("alias", ct.get_invalid_strs)
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("alias", ct.get_not_string)
def test_connection_disconnect_alias_param_check(self, alias):
"""
target: test disconnect passes wrong params of alias
......@@ -119,10 +113,10 @@ class TestConnectionParams(TestcaseBase):
expected: assert response is error
"""
# not check for alias
# check for alias
self._connect()
res = self.connection_wrap.disconnect(alias=alias)
log.info(res[0])
self.connection_wrap.disconnect(alias=alias, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.AliasType % type(alias)})
class TestConnectionOperation(TestcaseBase):
......@@ -146,7 +140,7 @@ class TestConnectionOperation(TestcaseBase):
alias2={"port": "-1", "host": "hostlocal"},
testing=data,
check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: err_msg})
check_items={ct.err_code: 0, ct.err_msg: err_msg})
# list all connections and check the response
self.connection_wrap.list_connections(check_task=ct.CheckTasks.ccr,
......@@ -293,10 +287,10 @@ class TestConnectionOperation(TestcaseBase):
self.connection_wrap.connect(alias="test_alias_name", host=host, port=port, check_task=ct.CheckTasks.ccr)
# add connection with diff params after that alias has been created
err_msg = cem.AliasExist % "test_alias_name"
err_msg = cem.ConnDiffConf % "test_alias_name"
self.connection_wrap.add_connection(test_alias_name={"host": "localhost", "port": "1"},
check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: err_msg})
check_items={ct.err_code: 0, ct.err_msg: err_msg})
# add connection with the same params
self.connection_wrap.add_connection(test_alias_name={"host": host, "port": port})
......@@ -313,10 +307,10 @@ class TestConnectionOperation(TestcaseBase):
check_task=ct.CheckTasks.ccr)
# add connection after that alias has been created
err_msg = cem.AliasExist % "test_alias_name"
err_msg = cem.ConnDiffConf % DefaultConfig.DEFAULT_USING
self.connection_wrap.add_connection(default={"host": "localhost", "port": "1"},
check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: err_msg})
check_items={ct.err_code: 0, ct.err_msg: err_msg})
# add connection with the same params
self.connection_wrap.add_connection(test_alias_name={"host": host, "port": port})
......@@ -380,9 +374,9 @@ class TestConnectionOperation(TestcaseBase):
"""
# create connection that param of alias is not exist
err_msg = cem.AliasNotExist % ct.Not_Exist
err_msg = cem.ConnLackConf % ct.Not_Exist
self.connection_wrap.connect(alias=ct.Not_Exist, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: err_msg})
check_items={ct.err_code: 0, ct.err_msg: err_msg})
# list all connections and check the response
self.connection_wrap.list_connections(check_task=ct.CheckTasks.ccr,
......@@ -469,10 +463,10 @@ class TestConnectionOperation(TestcaseBase):
assert res_obj1 == res_obj2
# connect twice with the different params
err_msg = cem.ConnectExist % "default"
err_msg = cem.ConnDiffConf % "default"
self.connection_wrap.connect(alias=connect_name, host="host", port=port,
check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1, ct.err_msg: err_msg})
check_items={ct.err_code: 0, ct.err_msg: err_msg})
@pytest.mark.tags(ct.CaseLabel.L2)
@pytest.mark.parametrize("connect_name", [DefaultConfig.DEFAULT_USING, "test_alias_nme"])
......@@ -511,8 +505,8 @@ class TestConnectionOperation(TestcaseBase):
# created connection with wrong connect name
self.connection_wrap.connect(alias=connect_name, ip=host, port=port, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: -1,
ct.err_msg: "Param is not complete. Please invoke as follow:"})
check_items={ct.err_code: 0,
ct.err_msg: cem.NoHostPort})
# list all connections and check the response
self.connection_wrap.list_connections(check_task=ct.CheckTasks.ccr,
......@@ -710,7 +704,7 @@ class TestConnectionOperation(TestcaseBase):
# init collection failed
self.collection_wrap.init_collection(name=collection_name, schema=schema, check_task=ct.CheckTasks.err_res,
check_items={ct.err_code: 0,
ct.err_msg: "object has no attribute 'has_collection'"},
ct.err_msg: cem.ConnectFirst},
_using=ct.Not_Exist)
@pytest.mark.tags(ct.CaseLabel.L1)
......
import pytest
from pymilvus_orm.default_config import DefaultConfig
from base.client_base import TestcaseBase
from common.code_mapping import ConnectionErrorMessage as cem
from common import common_func as cf
from common import common_type as ct
from common.common_type import CaseLabel, CheckTasks
......@@ -422,7 +425,7 @@ class TestQueryBase(TestcaseBase):
check_items=CheckTasks.err_res, check_task=error)
@pytest.mark.skip(reason="waiting for debug")
# @pytest.mark.skip(reason="waiting for debug")
class TestQueryOperation(TestcaseBase):
"""
******************************************************************
......@@ -430,19 +433,27 @@ class TestQueryOperation(TestcaseBase):
******************************************************************
"""
def test_query_without_connection(self):
@pytest.mark.tags(ct.CaseLabel.L3)
@pytest.mark.parametrize("collection_name", [cf.gen_unique_str(prefix)])
def test_query_without_connection(self, collection_name):
"""
target: test query without connection
method: close connect and query
expected: raise exception
"""
c_name = cf.gen_unique_str(prefix)
collection_w = self.init_collection_wrap(name=c_name)
self.connection_wrap.remove_connection(ct.default_alias)
res_list, _ = self.connection_wrap.list_connections()
assert ct.default_alias not in res_list
error = {ct.err_code: 1, ct.err_msg: 'should create connect first'}
collection_w.query(default_term_expr, check_task=CheckTasks.err_res, check_items=error)
# init a collection with default connection
collection_w = self.init_collection_wrap(name=collection_name)
# remove default connection
self.connection_wrap.remove_connection(alias=DefaultConfig.DEFAULT_USING)
# list connection to check
self.connection_wrap.list_connections(check_task=ct.CheckTasks.ccr, check_items={ct.list_content: []})
# query after remove default connection
collection_w.query(default_term_expr, check_task=CheckTasks.err_res,
check_items={ct.err_code: 0, ct.err_msg: cem.ConnectFirst})
def test_query_without_loading(self):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册