Unverified Commit 3c46b22d authored by del-zhenwu's avatar del-zhenwu Committed by GitHub
Browse files

add close cases (#2339)



* add close cases

Signed-off-by: default avatarzw <zw@milvus.io>

* fix case bug

Signed-off-by: default avatarzw <zw@milvus.io>

* reset case level

Signed-off-by: default avatarzw <zw@milvus.io>

* reset case level

Signed-off-by: default avatarzw <zw@milvus.io>

* fix case

Signed-off-by: default avatarzw <zw@milvus.io>

Co-authored-by: default avatarzw <zw@milvus.io>
parent 3c7c9ad6
Loading
Loading
Loading
Loading
+39 −32
Original line number Diff line number Diff line
@@ -55,17 +55,17 @@ def connect(request):
    return milvus


# @pytest.fixture(scope="module")
# def dis_connect(request):
#     ip = request.config.getoption("--ip")
#     port = request.config.getoption("--port")
#     http_port = request.config.getoption("--http-port")
#     handler = request.config.getoption("--handler")
#     if handler == "HTTP":
#         port = http_port
#     milvus = get_milvus(host=ip, port=port, handler=handler)
#     milvus.disconnect()
#     return milvus
@pytest.fixture(scope="module")
def dis_connect(request):
    ip = request.config.getoption("--ip")
    port = request.config.getoption("--port")
    http_port = request.config.getoption("--http-port")
    handler = request.config.getoption("--handler")
    if handler == "HTTP":
        port = http_port
    milvus = get_milvus(host=ip, port=port, handler=handler)
    milvus.close()
    return milvus


@pytest.fixture(scope="module")
@@ -108,8 +108,9 @@ def collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -134,8 +135,9 @@ def ip_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -160,8 +162,9 @@ def jac_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -185,8 +188,9 @@ def ham_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -210,8 +214,9 @@ def tanimoto_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -234,8 +239,9 @@ def substructure_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
@@ -258,8 +264,9 @@ def superstructure_collection(request, connect):
        pytest.exit("collection can not be created, exit pytest ...")

    def teardown():
        status, collection_names = connect.list_collections()
        for collection_name in collection_names:
        # status, collection_names = connect.list_collections()
        # for collection_name in collection_names:
        #     connect.drop_collection(collection_name)
        connect.drop_collection(collection_name)

    request.addfinalizer(teardown)
+12 −49
Original line number Diff line number Diff line
@@ -521,17 +521,17 @@ class TestAddBase:
            assert status.OK()
            assert len(ids) == nq

    # @pytest.mark.level(2)
    # def test_insert_without_connect(self, dis_connect, collection):
    #     '''
    #     target: test add vectors without connection
    #     method: create collection and add vectors in it, check if added successfully
    #     expected: raise exception
    #     '''
    #     nq = 5
    #     vectors = gen_vectors(nq, dim)
    #     with pytest.raises(Exception) as e:
    #         status, ids = dis_connect.insert(collection, vectors)
    @pytest.mark.level(2)
    def test_insert_without_connect(self, dis_connect, collection):
        '''
        target: test add vectors without connection
        method: create collection and add vectors in it, check if added successfully
        expected: raise exception
        '''
        nq = 5
        vectors = gen_vectors(nq, dim)
        with pytest.raises(Exception) as e:
            status, ids = dis_connect.insert(collection, vectors)

    def test_add_collection_not_existed(self, connect):
        '''
@@ -580,44 +580,6 @@ class TestAddBase:
        assert status.OK()
        assert len(result) == 1

    # TODO: enable
    # @pytest.mark.repeat(10)
    @pytest.mark.timeout(ADD_TIMEOUT)
    def _test_add_vector_with_multiprocessing(self, args):
        '''
        target: test add vectors, with multi processes
        method: 10 processed add vectors concurrently
        expected: status ok and result length is equal to the length off added vectors
        '''
        collection = gen_unique_str()
        param = {'collection_name': collection,
                 'dimension': dim,
                 'index_file_size': index_file_size,
                 'metric_type': MetricType.L2}
        milvus = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
        milvus.create_collection(param)
        vector = gen_single_vector(dim)
        process_num = 4
        loop_num = 5
        processes = []
        def add():
            milvus = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
            i = 0
            while i < loop_num:
                status, ids = milvus.insert(collection, vector)
                i = i + 1
            # milvus.disconnect()
        for i in range(process_num):
            p = Process(target=add, args=())
            processes.append(p)
            p.start()
            time.sleep(0.2)
        for p in processes:
            p.join()
        time.sleep(2)
        status, count = milvus.count_entities(collection)
        assert count == process_num * loop_num

    @pytest.mark.level(2)
    @pytest.mark.timeout(30)
    def test_collection_add_rows_count_multi_threading(self, args):
@@ -642,6 +604,7 @@ class TestAddBase:
        def add(thread_i):
            logging.getLogger().info("In thread-%d" % thread_i)
            milvus = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
            assert milvus
            status, result = milvus.insert(collection, records=vectors)
            assert status.OK()
            status = milvus.flush([collection])
+33 −98
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import pytest
import pdb
import threading
from multiprocessing import Process
import concurrent.futures
from utils import *

CONNECT_TIMEOUT = 12
@@ -18,30 +19,24 @@ class TestConnect:
        else:
            return False

    # def test_disconnect(self, connect):
    #     '''
    #     target: test disconnect
    #     method: disconnect a connected client
    #     expected: connect failed after disconnected
    #     '''
    #     res = connect.disconnect()
    #     assert res.OK()
    #     with pytest.raises(Exception) as e:
    #         res = connect.server_version()
    def test_disconnect(self, connect):
        '''
        target: test disconnect
        method: disconnect a connected client
        expected: connect failed after disconnected
        '''
        res = connect.close()
        with pytest.raises(Exception) as e:
            res = connect.server_version()

    # def test_disconnect_repeatedly(self, connect, args):
    #     '''
    #     target: test disconnect repeatedly
    #     method: disconnect a connected client, disconnect again
    #     expected: raise an error after disconnected
    #     '''
    #     if not connect.connected():
    #         with pytest.raises(Exception) as e:
    #             connect.disconnect()
    #     else:
    #         connect.disconnect()
    #         with pytest.raises(Exception) as e:
    #             connect.disconnect()
    def test_disconnect_repeatedly(self, dis_connect, args):
        '''
        target: test disconnect repeatedly
        method: disconnect a connected client, disconnect again
        expected: raise an error after disconnected
        '''
        with pytest.raises(Exception) as e:
            connect.close()

    def test_connect_correct_ip_port(self, args):
        '''
@@ -111,30 +106,21 @@ class TestConnect:
                milvus = get_milvus(None, None, uri=uri_value, handler=args["handler"])
                # assert not milvus.connected()

    # disable
    # def _test_connect_with_multiprocess(self, args):
    #     '''
    #     target: test uri connect with multiprocess
    #     method: set correct uri, test with multiprocessing connecting
    #     expected: all connection is connected        
    #     '''
    #     uri_value = "tcp://%s:%s" % (args["ip"], args["port"])
    #     process_num = 10
    #     processes = []

    #     def connect(milvus):
    #         milvus.connect(uri=uri_value)
    #         with pytest.raises(Exception) as e:
    #             milvus.connect(uri=uri_value)
    #         # assert milvus.connected()

    #     for i in range(process_num):
    #         milvus = get_milvus(args["ip"], args["port"], args["handler"])
    #         p = Process(target=connect, args=(milvus, ))
    #         processes.append(p)
    #         p.start()
    #     for p in processes:
    #         p.join()
    def test_connect_with_multiprocess(self, args):
        '''
        target: test uri connect with multiprocess
        method: set correct uri, test with multiprocessing connecting
        expected: all connection is connected        
        '''
        processes = []
        def connect():
            milvus = get_milvus(args["ip"], args["port"], handler=args["handler"])
            assert milvus           
        with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
            future_results = {executor.submit(
                connect): i for i in range(100)}
            for future in concurrent.futures.as_completed(future_results):
                future.result()

    def test_connect_repeatedly(self, args):
        '''
@@ -149,57 +135,6 @@ class TestConnect:
        milvus = Milvus(uri=uri_value, handler=args["handler"])
        # assert milvus.connected()

    # def test_connect_disconnect_repeatedly_times(self, args):
    #     '''
    #     target: test connect and disconnect for 10 times repeatedly
    #     method: disconnect, and then connect, assert connect status
    #     expected: status.code is 0
    #     '''
    #     times = 10
    #     for i in range(times):
    #         milvus = get_milvus(args["ip"], args["port"], handler=args["handler"])
    #         milvus.disconnect()
    #         assert not milvus.connected()

    # TODO: enable
    # def _test_connect_disconnect_with_multiprocess(self, args):
    #     '''
    #     target: test uri connect and disconnect repeatly with multiprocess
    #     method: set correct uri, test with multiprocessing connecting and disconnecting
    #     expected: all connection is connected after 10 times operation       
    #     '''
    #     uri_value = "tcp://%s:%s" % (args["ip"], args["port"])
    #     process_num = 4
    #     processes = []

    #     def connect(milvus):
    #         milvus.connect(uri=uri_value)
    #         milvus.disconnect()
    #         milvus.connect(uri=uri_value)
    #         assert milvus.connected()

    #     for i in range(process_num):
    #         milvus = get_milvus(args["ip"], args["port"], args["handler"])
    #         p = Process(target=connect, args=(milvus, ))
    #         processes.append(p)
    #         p.start()
    #     for p in processes:
    #         p.join()

    # Disable, (issue: https://github.com/milvus-io/milvus/issues/288)
    # def _test_connect_param_priority_both_hostip_uri(self, args):
    #     '''
    #     target: both host_ip_port / uri are both given, and not null, use the uri params
    #     method: check if wrong uri connection is ok
    #     expected: connect raise an exception and connected is false
    #     '''
    #     milvus = get_milvus(args["ip"], args["port"], args["handler"])
    #     uri_value = "tcp://%s:%s" % (args["ip"], args["port"])
    #     with pytest.raises(Exception) as e:
    #         res = milvus.connect(host=args["ip"], port=39540, uri=uri_value, timeout=1)
    #         logging.getLogger().info(res)
    #     # assert not milvus.connected()

    def _test_add_vector_and_disconnect_concurrently(self):
        '''
        Target: test disconnect in the middle of add vectors
+35 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import pdb
import threading
import logging
from multiprocessing import Pool, Process
import concurrent.futures
import pytest
from milvus import IndexType, MetricType
from utils import *
@@ -190,6 +191,40 @@ class TestGetBase:
        status, res = connect.get_entity_by_id(collection_new, [1]) 
        assert not status.OK()

    @pytest.mark.timeout(60)
    def test_get_vector_by_id_multithreads(self, connect, collection):
        vectors = gen_vectors(nb, dim)
        status, ids = connect.insert(collection, vectors)
        status = connect.flush([collection])
        assert status.OK()
        get_id = ids[100:200]
        def get():
            status, res = connect.get_entity_by_id(collection, get_id)
            assert status.OK()
            assert len(res) == len(get_id)
            for i in range(len(res)):
                assert_equal_vector(res[i], vectors[100+i])
        with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
            future_results = {executor.submit(
                get): i for i in range(10)}
            for future in concurrent.futures.as_completed(future_results):
                future.result()

    # TODO: autoflush
    def _test_get_vector_by_id_after_delete_no_flush(self, connect, collection):
        vectors = gen_vectors(nb, dim)
        status, ids = connect.insert(collection, vectors)
        status = connect.flush([collection])
        assert status.OK()
        get_id = ids[100:200]
        status = connect.delete_entity_by_id(collection, get_id)
        assert status.OK()
        status, res = connect.get_entity_by_id(collection, get_id)
        assert status.OK()
        assert len(res) == len(get_id)
        for i in range(len(res)):
            assert_equal_vector(res[i], vectors[100+i])


class TestGetIndexedVectors:
    """
+26 −26
Original line number Diff line number Diff line
@@ -23,27 +23,27 @@ class TestPing:
        status, msg = connect.server_status()
        assert status.OK()

    def _test_server_cmd_with_params_version(self, connect):
    def test_server_cmd_with_params_version(self, connect):
        '''
        target: test cmd: version
        method: cmd = "version" ...
        expected: when cmd = 'version', return version of server;
        '''
        cmd = "version"
        status, msg = connect.cmd(cmd)
        status, msg = connect._cmd(cmd)
        logging.getLogger().info(status)
        logging.getLogger().info(msg)
        assert status.OK()
        assert msg == __version__

    def _test_server_cmd_with_params_others(self, connect):
    def test_server_cmd_with_params_others(self, connect):
        '''
        target: test cmd: lalala
        method: cmd = "lalala" ...
        expected: when cmd = 'version', return version of server;
        '''
        cmd = "rm -rf test"
        status, msg = connect.cmd(cmd)
        status, msg = connect._cmd(cmd)
        logging.getLogger().info(status)
        logging.getLogger().info(msg)
        assert status.OK()
@@ -54,25 +54,25 @@ class TestPing:
        assert connect


# class TestPingDisconnect:
#     def test_server_version(self, dis_connect):
#         '''
#         target: test get the server version, after disconnect
#         method: call the server_version method after connected
#         expected: version should not be the pymilvus version
#         '''
#         res = None
#         with pytest.raises(Exception) as e:
#             status, res = connect.server_version()
#         assert res is None
# 
#     def test_server_status(self, dis_connect):
#         '''
#         target: test get the server status, after disconnect
#         method: call the server_status method after connected
#         expected: status returned should be not ok
#         '''
#         status = None
#         with pytest.raises(Exception) as e:
#             status, msg = connect.server_status()
#         assert status is None
class TestPingDisconnect:
    def test_server_version(self, dis_connect):
        '''
        target: test get the server version, after disconnect
        method: call the server_version method after connected
        expected: version should not be the pymilvus version
        '''
        res = None
        with pytest.raises(Exception) as e:
            status, res = connect.server_version()
        assert res is None

    def test_server_status(self, dis_connect):
        '''
        target: test get the server status, after disconnect
        method: call the server_status method after connected
        expected: status returned should be not ok
        '''
        status = None
        with pytest.raises(Exception) as e:
            status, msg = connect.server_status()
        assert status is None
Loading