test_ping.py 4.7 KB
Newer Older
J
JinHai-CN 已提交
1 2 3
import logging
import pytest

J
JinHai-CN 已提交
4
__version__ = '0.10.1'
J
JinHai-CN 已提交
5 6 7 8 9 10 11


class TestPing:
    def test_server_version(self, connect):
        '''
        target: test get the server version
        method: call the server_version method after connected
12
        expected: version should be the milvus version
J
JinHai-CN 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25
        '''
        status, res = connect.server_version()
        assert res == __version__

    def test_server_status(self, connect):
        '''
        target: test get the server status
        method: call the server_status method after connected
        expected: status returned should be ok
        '''
        status, msg = connect.server_status()
        assert status.OK()

D
del-zhenwu 已提交
26
    def test_server_cmd_with_params_version(self, connect):
J
JinHai-CN 已提交
27 28 29 30 31 32
        '''
        target: test cmd: version
        method: cmd = "version" ...
        expected: when cmd = 'version', return version of server;
        '''
        cmd = "version"
D
del-zhenwu 已提交
33
        status, msg = connect._cmd(cmd)
J
JinHai-CN 已提交
34 35 36 37 38
        logging.getLogger().info(status)
        logging.getLogger().info(msg)
        assert status.OK()
        assert msg == __version__

D
del-zhenwu 已提交
39
    def test_server_cmd_with_params_others(self, connect):
J
JinHai-CN 已提交
40 41 42 43 44 45
        '''
        target: test cmd: lalala
        method: cmd = "lalala" ...
        expected: when cmd = 'version', return version of server;
        '''
        cmd = "rm -rf test"
D
del-zhenwu 已提交
46
        status, msg = connect._cmd(cmd)
J
JinHai-CN 已提交
47 48 49 50 51 52
        logging.getLogger().info(status)
        logging.getLogger().info(msg)
        assert status.OK()
        # assert msg == __version__

    def test_connected(self, connect):
D
del-zhenwu 已提交
53 54
        # assert connect.connected()
        assert connect
J
JinHai-CN 已提交
55 56


57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
class TestPingWithTimeout:
    def test_server_version_legal_timeout(self, connect):
        '''
        target: test get the server version with legal timeout
        method: call the server_version method after connected with altering timeout
        expected: version should be the milvus version
        '''
        status, res = connect.server_version(20)
        assert res == __version__

    def test_server_version_negative_timeout(self, connect):
        '''
        target: test get the server version with negative timeout
        method: call the server_version method after connected with altering timeout
        expected: when timeout is illegal raises an error;
        '''
        status, res = connect.server_version(-1)
        assert not status.OK()

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

    def test_server_cmd_with_params_version_with_illegal_timeout(self, connect):
        '''
        target: test cmd: version and timeout
        method: cmd = "version" , timeout=-1
        expected: when timeout is illegal raises an error; 
        '''
        status, res = connect.server_version(-1)
        assert not status.OK()

    def test_server_cmd_with_params_others_with_illegal_timeout(self, connect):
        '''
        target: test cmd: lalala, timeout = -1
        method: cmd = "lalala", timeout = -1
        expected: when timeout is illegal raises an error;
        '''
        cmd = "rm -rf test"
        status, res = connect.server_version(-1)
        assert not status.OK()


D
del-zhenwu 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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
131 132 133 134 135 136 137 138 139 140 141

    def test_server_version_with_timeout(self, dis_connect):
        '''
        target: test get the server status with timeout settings 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(100)
        assert status is None