[test]Make pymilvus version compatible (#19824)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
This commit is contained in:
zhuwenxing 2022-10-18 13:09:30 +08:00 committed by GitHub
parent a4a6f60279
commit 3e11f2a700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 6 deletions

View File

@ -2,12 +2,14 @@ import h5py
import numpy as np
import time
from pathlib import Path
import pymilvus
from pymilvus import (
connections,
FieldSchema, CollectionSchema, DataType,
Collection
)
pymilvus_version = pymilvus.__version__
def read_benchmark_hdf5(file_path):
@ -58,7 +60,10 @@ def milvus_recall_test(host='127.0.0.1'):
t0 = time.time()
print(f"\nGet collection entities...")
collection.flush()
if pymilvus_version >= "2.2.0":
collection.flush()
else:
collection.num_entities
print(collection.num_entities)
t1 = time.time()
print(f"\nGet collection entities cost {t1 - t0:.4f} seconds")

View File

@ -1,10 +1,13 @@
import copy
import time
import pymilvus
from pymilvus import (
FieldSchema, CollectionSchema, DataType,
Collection, list_collections,
)
pymilvus_version = pymilvus.__version__
all_index_types = ["FLAT", "IVF_FLAT", "IVF_SQ8", "IVF_PQ", "HNSW", "ANNOY"]
default_index_params = [{"nlist": 128}, {"nlist": 128}, {"nlist": 128}, {"nlist": 128, "m": 16, "nbits": 8},
@ -55,7 +58,10 @@ def get_collections(prefix, check=False):
# list entities if collections
for name in col_list:
c = Collection(name=name)
c.flush()
if pymilvus_version >= "2.2.0":
c.flush()
else:
c.num_entities
num_entities = c.num_entities
print(f"{name}: {num_entities}")
if check:
@ -99,6 +105,10 @@ def create_collections_and_insert_data(prefix, flush=True, count=3000, collectio
if flush:
print("Get collection entities")
start_time = time.time()
if pymilvus_version >= "2.2.0":
collection.flush()
else:
collection.num_entities
print(f"collection entities: {collection.num_entities}")
end_time = time.time()
print("Get collection entities time = %.4fs" % (end_time - start_time))

View File

@ -1,4 +1,5 @@
import pytest
import pymilvus
from common import common_func as cf
from common import common_type as ct
from common.common_type import CaseLabel, CheckTasks
@ -8,6 +9,7 @@ from deploy.base import TestDeployBase
from deploy.common import gen_index_param, gen_search_param
from utils.util_log import test_log as log
pymilvus_version = pymilvus.__version__
default_nb = ct.default_nb
default_nq = ct.default_nq
@ -134,7 +136,10 @@ class TestActionFirstDeployment(TestDeployBase):
self.init_collection_general(insert_data=True, is_binary=is_binary, nb=data_size,
is_flush=False, is_index=True, name=name)
# at this step, all segment are sealed
collection_w.flush()
if pymilvus_version >= "2.2.0":
collection_w.flush()
else:
collection_w.collection.num_entities
# delete data for sealed segment and before index
delete_expr = f"{ct.default_int64_field_name} in {[i for i in range(10,20)]}"
if is_deleted == "is_deleted":

View File

@ -1,4 +1,5 @@
import pytest
import pymilvus
from common import common_func as cf
from common import common_type as ct
from common.common_type import CaseLabel, CheckTasks
@ -23,7 +24,7 @@ binary_field_name = default_binary_vec_field_name
default_search_exp = "int64 >= 0"
default_term_expr = f'{ct.default_int64_field_name} in [0, 1]'
pymilvus_version = pymilvus.__version__
class TestActionSecondDeployment(TestDeployBase):
""" Test case of action before reinstall """
@ -121,7 +122,10 @@ class TestActionSecondDeployment(TestDeployBase):
check_task=check_task)
# flush
collection_w.num_entities
if pymilvus_version >= "2.2.0":
collection_w.flush()
else:
collection_w.collection.num_entities
# search and query
if "empty" in name:
@ -146,7 +150,10 @@ class TestActionSecondDeployment(TestDeployBase):
for i in range(2):
self.init_collection_general(insert_data=True, is_binary=is_binary, nb=data_size,
is_flush=False, is_index=True, name=name)
collection_w.num_entities
if pymilvus_version >= "2.2.0":
collection_w.flush()
else:
collection_w.collection.num_entities
# delete data
delete_expr = f"{ct.default_int64_field_name} in [0,1,2,3,4,5,6,7,8,9]"