Commit b78863cc authored by zhenwu's avatar zhenwu
Browse files

fix test case for open-version


Former-commit-id: 89a3ef5721123ef12d6a2546c441e09307d80a81
parent 700ea39f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@ allure-pytest==2.7.0
pytest-print==0.1.2
pytest-level==0.1.1
six==1.12.0
thrift==0.11.0
typed-ast==1.3.5
wcwidth==0.1.7
wrapt==1.11.1
zipp==0.5.1
scikit-learn>=0.19.1
pymilvus-test>=0.2.0
 No newline at end of file
+73 −60
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@ ADD_TIMEOUT = 60
nprobe = 1
epsilon = 0.0001

index_params = random.choice(gen_index_params())
logging.getLogger().info(index_params)


class TestAddBase:
    """
@@ -26,6 +23,15 @@ class TestAddBase:
      The following cases are used to test `add_vectors / index / search / delete` mixed function
    ******************************************************************
    """
    @pytest.fixture(
        scope="function",
        params=gen_simple_index_params()
    )
    def get_simple_index_params(self, request, args):
        if "internal" not in args:
            if request.param["index_type"] == IndexType.IVF_SQ8H:
                pytest.skip("sq8h not support in open source")
        return request.param

    def test_add_vector_create_table(self, connect, table):
        '''
@@ -71,7 +77,7 @@ class TestAddBase:
        method: delete table_2 and add vector to table_1
        expected: status ok
        '''
        param = {'table_name': 'test_delete_table_add_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -79,7 +85,6 @@ class TestAddBase:
        status = connect.delete_table(table)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(param['table_name'], vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -101,14 +106,13 @@ class TestAddBase:
        method: add vector and delete table
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_delete_another_table',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        status = connect.create_table(param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        status = connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -131,7 +135,7 @@ class TestAddBase:
        method: add vector , sleep, and delete table
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_delete_another_table',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -143,86 +147,91 @@ class TestAddBase:
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_create_index_add_vector(self, connect, table):
    def test_create_index_add_vector(self, connect, table, get_simple_index_params):
        '''
        target: test add vector after build index
        method: build index and add vector
        expected: status ok
        '''
        status = connect.create_index(table, index_params)
        index_param = get_simple_index_params
        status = connect.create_index(table, index_param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_create_index_add_vector_another(self, connect, table):
    def test_create_index_add_vector_another(self, connect, table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_create_index_add_vector_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        status = connect.create_table(param)
        status = connect.create_index(table, index_params)
        status = connect.create_index(table, index_param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_create_index(self, connect, table):
    def test_add_vector_create_index(self, connect, table, get_simple_index_params):
        '''
        target: test build index add after vector
        method: add vector and build index
        expected: status ok
        '''
        index_param = get_simple_index_params
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        status = connect.create_index(table, index_params)
        status = connect.create_index(table, index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_create_index_another(self, connect, table):
    def test_add_vector_create_index_another(self, connect, table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_create_index_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        status = connect.create_table(param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        status = connect.create_index(param['table_name'], index_params)
        connect.delete_table(param['table_name'])
        status = connect.create_index(param['table_name'], index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_sleep_create_index(self, connect, table):
    def test_add_vector_sleep_create_index(self, connect, table, get_simple_index_params):
        '''
        target: test build index add after vector for a while
        method: add vector and build index
        expected: status ok
        '''
        index_param = get_simple_index_params
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        time.sleep(1)
        status = connect.create_index(table, index_params)
        status = connect.create_index(table, index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_sleep_create_index_another(self, connect, table):
    def test_add_vector_sleep_create_index_another(self, connect, table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1 for a while
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_create_index_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -230,8 +239,7 @@ class TestAddBase:
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        time.sleep(1)
        status = connect.create_index(param['table_name'], index_params)
        connect.delete_table(param['table_name'])
        status = connect.create_index(param['table_name'], index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -253,7 +261,7 @@ class TestAddBase:
        method: search table and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_search_vector_add_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -261,7 +269,6 @@ class TestAddBase:
        vector = gen_single_vector(dim)
        status, result = connect.search_vectors(table, 1, nprobe, vector)
        status, ids = connect.add_vectors(param['table_name'], vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -283,7 +290,7 @@ class TestAddBase:
        method: search table and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_search_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -291,7 +298,6 @@ class TestAddBase:
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(table, vector)
        status, result = connect.search_vectors(param['table_name'], 1, nprobe, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -314,7 +320,7 @@ class TestAddBase:
        method: search table , sleep, and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_search_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -323,7 +329,6 @@ class TestAddBase:
        status, ids = connect.add_vectors(table, vector)
        time.sleep(1)
        status, result = connect.search_vectors(param['table_name'], 1, nprobe, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    """
@@ -594,6 +599,15 @@ class TestAddIP:
      The following cases are used to test `add_vectors / index / search / delete` mixed function
    ******************************************************************
    """
    @pytest.fixture(
        scope="function",
        params=gen_simple_index_params()
    )
    def get_simple_index_params(self, request, args):
        if "internal" not in args:
            if request.param["index_type"] == IndexType.IVF_SQ8H:
                pytest.skip("sq8h not support in open source")
        return request.param

    def test_add_vector_create_table(self, connect, ip_table):
        '''
@@ -639,7 +653,7 @@ class TestAddIP:
        method: delete table_2 and add vector to table_1
        expected: status ok
        '''
        param = {'table_name': 'test_delete_table_add_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -647,7 +661,6 @@ class TestAddIP:
        status = connect.delete_table(ip_table)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(param['table_name'], vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -699,7 +712,7 @@ class TestAddIP:
        method: add vector , sleep, and delete table
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_delete_another_table',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -711,86 +724,90 @@ class TestAddIP:
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_create_index_add_vector(self, connect, ip_table):
    def test_create_index_add_vector(self, connect, ip_table, get_simple_index_params):
        '''
        target: test add vector after build index
        method: build index and add vector
        expected: status ok
        '''
        status = connect.create_index(ip_table, index_params)
        index_param = get_simple_index_params
        status = connect.create_index(ip_table, index_param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_create_index_add_vector_another(self, connect, ip_table):
    def test_create_index_add_vector_another(self, connect, ip_table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_create_index_add_vector_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        status = connect.create_table(param)
        status = connect.create_index(ip_table, index_params)
        status = connect.create_index(ip_table, index_param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_create_index(self, connect, ip_table):
    def test_add_vector_create_index(self, connect, ip_table, get_simple_index_params):
        '''
        target: test build index add after vector
        method: add vector and build index
        expected: status ok
        '''
        index_param = get_simple_index_params
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        status = connect.create_index(ip_table, index_params)
        status = connect.create_index(ip_table, index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_create_index_another(self, connect, ip_table):
    def test_add_vector_create_index_another(self, connect, ip_table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_create_index_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        status = connect.create_table(param)
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        status = connect.create_index(param['table_name'], index_params)
        connect.delete_table(param['table_name'])
        status = connect.create_index(param['table_name'], index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_sleep_create_index(self, connect, ip_table):
    def test_add_vector_sleep_create_index(self, connect, ip_table, get_simple_index_params):
        '''
        target: test build index add after vector for a while
        method: add vector and build index
        expected: status ok
        '''
        index_param = get_simple_index_params
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        time.sleep(1)
        status = connect.create_index(ip_table, index_params)
        status = connect.create_index(ip_table, index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
    def test_add_vector_sleep_create_index_another(self, connect, ip_table):
    def test_add_vector_sleep_create_index_another(self, connect, ip_table, get_simple_index_params):
        '''
        target: test add vector to table_2 after build index for table_1 for a while
        method: build index and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_create_index_another',
        index_param = get_simple_index_params
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -798,8 +815,7 @@ class TestAddIP:
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        time.sleep(1)
        status = connect.create_index(param['table_name'], index_params)
        connect.delete_table(param['table_name'])
        status = connect.create_index(param['table_name'], index_param)
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -821,7 +837,7 @@ class TestAddIP:
        method: search table and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_search_vector_add_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -829,7 +845,6 @@ class TestAddIP:
        vector = gen_single_vector(dim)
        status, result = connect.search_vectors(ip_table, 1, nprobe, vector)
        status, ids = connect.add_vectors(param['table_name'], vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -851,7 +866,7 @@ class TestAddIP:
        method: search table and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_search_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -859,7 +874,6 @@ class TestAddIP:
        vector = gen_single_vector(dim)
        status, ids = connect.add_vectors(ip_table, vector)
        status, result = connect.search_vectors(param['table_name'], 1, nprobe, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    @pytest.mark.timeout(ADD_TIMEOUT)
@@ -882,7 +896,7 @@ class TestAddIP:
        method: search table , sleep, and add vector
        expected: status ok
        '''
        param = {'table_name': 'test_add_vector_sleep_search_vector_another',
        param = {'table_name': gen_unique_str(),
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
@@ -891,7 +905,6 @@ class TestAddIP:
        status, ids = connect.add_vectors(ip_table, vector)
        time.sleep(1)
        status, result = connect.search_vectors(param['table_name'], 1, nprobe, vector)
        connect.delete_table(param['table_name'])
        assert status.OK()

    """
@@ -1130,7 +1143,7 @@ class TestAddIP:
        nq = 100
        vectors = gen_vectors(nq, dim)
        table_list = []
        for i in range(50):
        for i in range(20):
            table_name = gen_unique_str('test_add_vector_multi_tables')
            table_list.append(table_name)
            param = {'table_name': table_name,
@@ -1140,7 +1153,7 @@ class TestAddIP:
            connect.create_table(param)
        time.sleep(2)
        for j in range(10):
            for i in range(50):
            for i in range(20):
                status, ids = connect.add_vectors(table_name=table_list[i], records=vectors)
                assert status.OK()

+13 −16
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import pdb
import threading
from multiprocessing import Pool, Process
import numpy
import sklearn.preprocessing
from milvus import Milvus, IndexType, MetricType
from utils import *

@@ -15,7 +16,7 @@ nb = 10000
dim = 128
index_file_size = 10
vectors = gen_vectors(nb, dim)
vectors /= numpy.linalg.norm(vectors)
vectors = sklearn.preprocessing.normalize(vectors, axis=1, norm='l2')
vectors = vectors.tolist()
BUILD_TIMEOUT = 60
nprobe = 1
@@ -218,29 +219,26 @@ class TestIndexBase:
        assert status.OK()

    @pytest.mark.timeout(BUILD_TIMEOUT)
    def test_create_index_no_vectors_then_add_vectors(self, connect, table):
    def test_create_index_no_vectors_then_add_vectors(self, connect, table, get_simple_index_params):
        '''
        target: test create index interface when there is no vectors in table, and does not affect the subsequent process
        method: create table and add no vectors in it, and then create index, add vectors in it
        expected: return code equals to 0
        '''
        nlist = 16384
        index_param = {"index_type": IndexType.IVF_SQ8, "nlist": nlist}
        index_param = get_simple_index_params
        status = connect.create_index(table, index_param)
        status, ids = connect.add_vectors(table, vectors)
        assert status.OK()

    @pytest.mark.timeout(BUILD_TIMEOUT)
    def test_create_same_index_repeatedly(self, connect, table):
    def test_create_same_index_repeatedly(self, connect, table, get_simple_index_params):
        '''
        target: check if index can be created repeatedly, with the same create_index params
        method: create index after index have been built
        expected: return code success, and search ok
        '''
        nlist = 16384
        status, ids = connect.add_vectors(table, vectors)
        index_param = {"index_type": IndexType.IVF_SQ8, "nlist": nlist}
        # index_params = get_index_params
        index_param = get_simple_index_params
        status = connect.create_index(table, index_param)
        status = connect.create_index(table, index_param)
        assert status.OK()
@@ -390,9 +388,9 @@ class TestIndexBase:
        method: create table and add vectors in it, create index, call drop index
        expected: return code 0, and default index param
        '''
        index_params = get_index_params
        index_param = get_index_params
        status, ids = connect.add_vectors(table, vectors)
        status = connect.create_index(table, index_params)
        status = connect.create_index(table, index_param)
        assert status.OK()
        status, result = connect.describe_index(table)
        logging.getLogger().info(result)
@@ -404,15 +402,15 @@ class TestIndexBase:
        assert result._table_name == table
        assert result._index_type == IndexType.FLAT

    def test_drop_index_repeatly(self, connect, table, get_simple_index_params):
    def test_drop_index_repeatly(self, connect, table, get_index_params):
        '''
        target: test drop index repeatly
        method: create index, call drop index, and drop again
        expected: return code 0
        '''
        index_params = get_simple_index_params
        index_param = get_index_params
        status, ids = connect.add_vectors(table, vectors)
        status = connect.create_index(table, index_params)
        status = connect.create_index(table, index_param)
        assert status.OK()
        status, result = connect.describe_index(table)
        logging.getLogger().info(result)
@@ -688,14 +686,13 @@ class TestIndexIP:
        assert status.OK()

    @pytest.mark.timeout(BUILD_TIMEOUT)
    def test_create_index_no_vectors_then_add_vectors(self, connect, ip_table):
    def test_create_index_no_vectors_then_add_vectors(self, connect, ip_table, get_simple_index_params):
        '''
        target: test create index interface when there is no vectors in table, and does not affect the subsequent process
        method: create table and add no vectors in it, and then create index, add vectors in it
        expected: return code equals to 0
        '''
        nlist = 16384
        index_param = {"index_type": IndexType.IVF_SQ8, "nlist": nlist}
        index_param = get_simple_index_params
        status = connect.create_index(ip_table, index_param)
        status, ids = connect.add_vectors(ip_table, vectors)
        assert status.OK()
+10 −7

File changed.

Preview size limit exceeded, changes collapsed.

+19 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading