Skip to content

Commit

Permalink
test: Refactor pymilvus client v2 testbase and add a test for search …
Browse files Browse the repository at this point in the history
…hint (#38939)

issue: #38877
1. refactor pymilvus client v2 testcasebase
2. add a test for search hint
3. update pymilvus to 2.6

---------

Signed-off-by: yanliang567 <[email protected]>
  • Loading branch information
yanliang567 authored Jan 6, 2025
1 parent f0cddfd commit 731e882
Show file tree
Hide file tree
Showing 17 changed files with 3,830 additions and 3,060 deletions.
31 changes: 14 additions & 17 deletions tests/python_client/base/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from base.index_wrapper import ApiIndexWrapper
from base.utility_wrapper import ApiUtilityWrapper
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
from base.high_level_api_wrapper import HighLevelApiWrapper
from base.async_milvus_client_wrapper import AsyncMilvusClientWrapper
from utils.util_log import test_log as log
from common import common_func as cf
Expand All @@ -33,9 +32,8 @@ class Base:
collection_schema_wrap = None
field_schema_wrap = None
database_wrap = None
collection_object_list = []
tear_down_collection_names = []
resource_group_list = []
high_level_api_wrap = None
async_milvus_client_wrap = None
skip_connection = False

Expand All @@ -60,7 +58,6 @@ def _setup_objects(self):
self.collection_schema_wrap = ApiCollectionSchemaWrapper()
self.field_schema_wrap = ApiFieldSchemaWrapper()
self.database_wrap = ApiDatabaseWrapper()
self.high_level_api_wrap = HighLevelApiWrapper()
self.async_milvus_client_wrap = AsyncMilvusClientWrapper()

def teardown_method(self, method):
Expand All @@ -83,9 +80,9 @@ def _teardown_objects(self):
self.collection_wrap.drop(check_task=ct.CheckTasks.check_nothing)

collection_list = self.utility_wrap.list_collections()[0]
for collection_object in self.collection_object_list:
if collection_object.collection is not None and collection_object.name in collection_list:
collection_object.drop(check_task=ct.CheckTasks.check_nothing)
for collection_name in self.tear_down_collection_names:
if collection_name is not None and collection_name in collection_list:
self.collection_wrap.init_collection(name=collection_name)[0].drop()

""" Clean up the rgs before disconnect """
rgs_list = self.utility_wrap.list_resource_groups()[0]
Expand Down Expand Up @@ -169,15 +166,15 @@ def _connect(self, enable_milvus_client_api=False):
log.info(f"server version: {server_version}")
return res

def init_async_milvus_client(self):
uri = cf.param_info.param_uri or f"http://{cf.param_info.param_host}:{cf.param_info.param_port}"
kwargs = {
"uri": uri,
"user": cf.param_info.param_user,
"password": cf.param_info.param_password,
"token": cf.param_info.param_token,
}
self.async_milvus_client_wrap.init_async_client(**kwargs)
# def init_async_milvus_client(self):
# uri = cf.param_info.param_uri or f"http://{cf.param_info.param_host}:{cf.param_info.param_port}"
# kwargs = {
# "uri": uri,
# "user": cf.param_info.param_user,
# "password": cf.param_info.param_password,
# "token": cf.param_info.param_token,
# }
# self.async_milvus_client_wrap.init_async_client(**kwargs)

def init_collection_wrap(self, name=None, schema=None, check_task=None, check_items=None,
enable_dynamic_field=False, with_json=True, **kwargs):
Expand All @@ -189,7 +186,7 @@ def init_collection_wrap(self, name=None, schema=None, check_task=None, check_it
collection_w = ApiCollectionWrapper()
collection_w.init_collection(name=name, schema=schema, check_task=check_task,
check_items=check_items, **kwargs)
self.collection_object_list.append(collection_w)
self.tear_down_collection_names.append(name)
return collection_w

def init_multi_fields_collection_wrap(self, name=cf.gen_unique_str()):
Expand Down
867 changes: 867 additions & 0 deletions tests/python_client/base/client_v2_base.py

Large diffs are not rendered by default.

1,700 changes: 850 additions & 850 deletions tests/python_client/base/high_level_api_wrapper.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/python_client/check/func_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def check_permission_deny(res, actual=True):
def check_auth_failure(res, actual=True):
assert actual is False
if isinstance(res, Error):
assert "auth" in res.message
assert "auth check failure" in res.message
else:
log.error("[CheckFunc] Response of API is not an error: %s" % str(res))
assert False
Expand Down
255 changes: 121 additions & 134 deletions tests/python_client/milvus_client/test_milvus_client_alias.py

Large diffs are not rendered by default.

306 changes: 135 additions & 171 deletions tests/python_client/milvus_client/test_milvus_client_alter.py

Large diffs are not rendered by default.

680 changes: 336 additions & 344 deletions tests/python_client/milvus_client/test_milvus_client_collection.py

Large diffs are not rendered by default.

163 changes: 75 additions & 88 deletions tests/python_client/milvus_client/test_milvus_client_delete.py

Large diffs are not rendered by default.

471 changes: 229 additions & 242 deletions tests/python_client/milvus_client/test_milvus_client_index.py

Large diffs are not rendered by default.

558 changes: 274 additions & 284 deletions tests/python_client/milvus_client/test_milvus_client_insert.py

Large diffs are not rendered by default.

522 changes: 255 additions & 267 deletions tests/python_client/milvus_client/test_milvus_client_partition.py

Large diffs are not rendered by default.

258 changes: 123 additions & 135 deletions tests/python_client/milvus_client/test_milvus_client_query.py

Large diffs are not rendered by default.

386 changes: 190 additions & 196 deletions tests/python_client/milvus_client/test_milvus_client_rbac.py

Large diffs are not rendered by default.

416 changes: 229 additions & 187 deletions tests/python_client/milvus_client/test_milvus_client_search.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/python_client/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pytest-parallel
pytest-random-order

# pymilvus
pymilvus==2.5.2rc3
pymilvus[bulk_writer]==2.5.2rc3
pymilvus==2.6.0rc44
pymilvus[bulk_writer]==2.6.0rc44


# for customize config test
Expand Down
48 changes: 24 additions & 24 deletions tests/python_client/testcases/async_milvus_client/test_e2e_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
from pymilvus.client.types import LoadState, DataType
from pymilvus import AnnSearchRequest, RRFRanker

from base.client_base import TestcaseBase
from base.client_v2_base import TestMilvusClientV2Base
from common import common_func as cf
from common import common_type as ct
from common.common_type import CaseLabel, CheckTasks
from utils.util_log import test_log as log

pytestmark = pytest.mark.asyncio

prefix = "async"
async_default_nb = 5000
default_pk_name = "id"
default_vector_name = "vector"


class TestAsyncMilvusClient(TestcaseBase):
class TestAsyncMilvusClient(TestMilvusClientV2Base):

def teardown_method(self, method):
self.init_async_milvus_client()
loop = asyncio.get_event_loop()
loop.run_until_complete(self.async_milvus_client_wrap.close())
super().teardown_method(method)

@pytest.mark.tags(CaseLabel.L0)
async def test_async_client_default(self):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
self.init_async_milvus_client()

# create collection
c_name = cf.gen_unique_str(prefix)
await self.async_milvus_client_wrap.create_collection(c_name, dimension=ct.default_dim)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections

# insert entities
Expand Down Expand Up @@ -116,17 +116,17 @@ async def test_async_client_default(self):
@pytest.mark.tags(CaseLabel.L0)
async def test_async_client_partition(self):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
self.init_async_milvus_client()

# create collection & partition
c_name = cf.gen_unique_str(prefix)
p_name = cf.gen_unique_str("par")
await self.async_milvus_client_wrap.create_collection(c_name, dimension=ct.default_dim)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections
self.high_level_api_wrap.create_partition(milvus_client, c_name, p_name)
partitions, _ = self.high_level_api_wrap.list_partitions(milvus_client, c_name)
self.create_partition(milvus_client, c_name, p_name)
partitions, _ = self.list_partitions(milvus_client, c_name)
assert p_name in partitions

# insert entities
Expand Down Expand Up @@ -216,7 +216,7 @@ async def test_async_client_partition(self):
@pytest.mark.tags(CaseLabel.L0)
async def test_async_client_with_schema(self, schema):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
self.init_async_milvus_client()

# create collection
Expand All @@ -228,7 +228,7 @@ async def test_async_client_with_schema(self, schema):
schema.add_field(ct.default_float_vec_field_name, DataType.FLOAT_VECTOR, dim=ct.default_dim)
schema.add_field(default_vector_name, DataType.FLOAT_VECTOR, dim=ct.default_dim)
await self.async_milvus_client_wrap.create_collection(c_name, schema=schema)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections

# insert entities
Expand All @@ -251,12 +251,12 @@ async def test_async_client_with_schema(self, schema):
assert r[0]['insert_count'] == step

# flush
self.high_level_api_wrap.flush(milvus_client, c_name)
stats, _ = self.high_level_api_wrap.get_collection_stats(milvus_client, c_name)
self.flush(milvus_client, c_name)
stats, _ = self.get_collection_stats(milvus_client, c_name)
assert stats["row_count"] == async_default_nb

# create index -> load
index_params, _ = self.high_level_api_wrap.prepare_index_params(milvus_client,
index_params, _ = self.prepare_index_params(milvus_client,
field_name=ct.default_float_vec_field_name,
index_type="HNSW", metric_type="COSINE", M=30,
efConstruction=200)
Expand All @@ -265,10 +265,10 @@ async def test_async_client_with_schema(self, schema):
await self.async_milvus_client_wrap.create_index(c_name, index_params)
await self.async_milvus_client_wrap.load_collection(c_name)

_index, _ = self.high_level_api_wrap.describe_index(milvus_client, c_name, default_vector_name)
_index, _ = self.describe_index(milvus_client, c_name, default_vector_name)
assert _index["indexed_rows"] == async_default_nb
assert _index["state"] == "Finished"
_load, _ = self.high_level_api_wrap.get_load_state(milvus_client, c_name)
_load, _ = self.get_load_state(milvus_client, c_name)
assert _load["state"] == LoadState.Loaded

# dql tasks
Expand Down Expand Up @@ -320,13 +320,13 @@ async def test_async_client_with_schema(self, schema):
@pytest.mark.tags(CaseLabel.L0)
async def test_async_client_dml(self):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
self.init_async_milvus_client()

# create collection
c_name = cf.gen_unique_str(prefix)
await self.async_milvus_client_wrap.create_collection(c_name, dimension=ct.default_dim)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections

# insert entities
Expand Down Expand Up @@ -377,18 +377,18 @@ async def test_async_client_dml(self):
@pytest.mark.tags(CaseLabel.L2)
async def test_async_client_with_db(self):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
db_name = cf.gen_unique_str("db")
self.high_level_api_wrap.create_database(milvus_client, db_name)
self.high_level_api_wrap.close(milvus_client)
self.create_database(milvus_client, db_name)
self.close(milvus_client)
uri = cf.param_info.param_uri or f"http://{cf.param_info.param_host}:{cf.param_info.param_port}"
milvus_client, _ = self.connection_wrap.MilvusClient(uri=uri, db_name=db_name)
self.async_milvus_client_wrap.init_async_client(uri, db_name=db_name)

# create collection
c_name = cf.gen_unique_str(prefix)
await self.async_milvus_client_wrap.create_collection(c_name, dimension=ct.default_dim)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections

# insert entities
Expand Down Expand Up @@ -458,7 +458,7 @@ async def test_async_client_close(self):
@pytest.mark.skip("connect with zilliz cloud")
async def test_async_client_with_token(self):
# init client
milvus_client = self._connect(enable_milvus_client_api=True)
milvus_client = self._client()
uri = cf.param_info.param_uri or f"http://{cf.param_info.param_host}:{cf.param_info.param_port}"
token = cf.param_info.param_token
milvus_client, _ = self.connection_wrap.MilvusClient(uri=uri, token=token)
Expand All @@ -467,7 +467,7 @@ async def test_async_client_with_token(self):
# create collection
c_name = cf.gen_unique_str(prefix)
await self.async_milvus_client_wrap.create_collection(c_name, dimension=ct.default_dim)
collections, _ = self.high_level_api_wrap.list_collections(milvus_client)
collections, _ = self.list_collections(milvus_client)
assert c_name in collections

# insert entities
Expand Down
Loading

0 comments on commit 731e882

Please sign in to comment.