未验证 提交 dd5078ad 编写于 作者: D del-zhenwu 提交者: GitHub

[skip ci] Http case (#3908)

* add http case
Signed-off-by: Nzw <zw@milvus.io>

* fix test_ping
Signed-off-by: Nzw <zw@milvus.io>
Co-authored-by: Nzw <zw@milvus.io>
上级 c0ee8345
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
.env
*/bin
*/obj
README.md
LICENSE
.vscode
__pycache__
\ No newline at end of file
.python-version
.pytest_cache
__pycache__
.vscode
.idea
test_out/
*.pyc
db/
logs/
.coverage
FROM python:3.6.8-jessie
LABEL Name=megasearch_engine_test Version=0.0.1
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get install -y --no-install-recommends \
libc-dev build-essential && \
python3 -m pip install -r requirements.txt && \
apt-get remove --purge -y && \
rm -rf /var/lib/apt/lists/*
ENTRYPOINT [ "/app/docker-entrypoint.sh" ]
CMD [ "start" ]
\ No newline at end of file
## Requirements
* python 3.6.8+
* pip install -r requirements.txt
## How to Build Test Env
```shell
sudo docker pull registry.zilliz.com/milvus/milvus-test:v0.2
sudo docker run -it -v /home/zilliz:/home/zilliz -d registry.zilliz.com/milvus/milvus-test:v0.2
```
## How to Create Test Env docker in k8s
```shell
# 1. start milvus k8s pod
cd milvus-helm/charts/milvus
helm install --wait --timeout 300s \
--set image.repository=registry.zilliz.com/milvus/engine \
--set persistence.enabled=true \
--set image.tag=PR-3818-gpu-centos7-release \
--set image.pullPolicy=Always \
--set service.type=LoadBalancer \
-f ci/db_backend/mysql_gpu_values.yaml \
-f ci/filebeat/values.yaml \
-f test.yaml \
--namespace milvus \
milvus-ci-pr-3818-1-single-centos7-gpu .
# 2. remove milvus k8s pod
helm uninstall -n milvus milvus-test
# 3. check k8s pod status
kubectl get svc -n milvus -w milvus-test
# 4. login to pod
kubectl get pods --namespace milvus
kubectl exec -it milvus-test-writable-6cc49cfcd4-rbrns -n milvus bash
```
## How to Run Test cases
```shell
# Test level-1 cases
pytest . --level=1 --ip=127.0.0.1 --port=19530
# Test level-1 cases in 'test_connect.py' only
pytest test_connect.py --level=1
```
## How to list test cases
```shell
# List all cases
pytest --dry-run -qq
# Collect all cases with docstring
pytest --collect-only -qq
# Create test report with allure
pytest --alluredir=test_out . -q -v
allure serve test_out
```
## Contribution getting started
* Follow PEP-8 for naming and black for formatting.
import logging
import pdb
import json
import requests
import utils
from milvus import Milvus
from utils import *
url_collections = "collections"
url_system = "system/"
class Request(object):
def __init__(self, url):
self._url = url
def _check_status(self, result):
logging.getLogger().info(result.text)
if result.status_code not in [200, 201, 204]:
return False
if not result.text or "code" not in json.loads(result.text):
return True
elif json.loads(result.text)["code"] == 0:
return True
else:
logging.getLogger().error(result.status_code)
logging.getLogger().error(result.reason)
return False
def get(self, data=None):
res_get = requests.get(self._url, params=data)
if self._check_status(res_get):
# TODO:
return json.loads(res_get.text)
def post(self, data):
res_post = requests.post(self._url, data=json.dumps(data))
return self._check_status(res_post)
def delete(self, data=None):
if data:
res_delete = requests.delete(self._url, data=json.dumps(data))
else:
res_delete = requests.delete(self._url)
return self._check_status(res_delete)
class MilvusClient(object):
def __init__(self, url):
self._url = url
def create_collection(self, collection_name, fields):
url = self._url+url_collections
r = Request(url)
fields.update({"collection_name": collection_name})
try:
return r.post(fields)
except Exception as e:
logging.getLogger().error(str(e))
return False
def list_collections(self):
url = self._url+url_collections
r = Request(url)
try:
collections = r.get()
return collections["collections"]
except Exception as e:
logging.getLogger().error(str(e))
return False
def has_collection(self, collection_name):
url = self._url+url_collections+'/'+collection_name
r = Request(url)
try:
return r.get()
except Exception as e:
logging.getLogger().error(str(e))
return False
def drop_collection(self, collection_name):
url = self._url+url_collections+'/'+collection_name
r = Request(url)
try:
res_drop = r.delete()
except Exception as e:
logging.getLogger().error(str(e))
return False
def get_entity(self, ids):
url = None
r = Request(url)
try:
collections = r.get()["entity"]
except Exception as e:
logging.getLogger().error(str(e))
return False
def system_cmd(self, cmd):
url = self._url+url_system+cmd
r = Request(url)
try:
return r.get()["reply"]
except Exception as e:
logging.getLogger().error(str(e))
return False
import pdb
import logging
import socket
import pytest
import requests
from utils import gen_unique_str
from client import MilvusClient
from utils import *
timeout = 60
dimension = 128
delete_timeout = 60
def pytest_addoption(parser):
parser.addoption("--ip", action="store", default="localhost")
parser.addoption("--service", action="store", default="")
parser.addoption("--port", action="store", default=19530)
parser.addoption("--tag", action="store", default="all", help="only run tests matching the tag.")
parser.addoption('--dry-run', action='store_true', default=False)
def pytest_configure(config):
# register an additional marker
config.addinivalue_line(
"markers", "tag(name): mark test to run only matching the tag"
)
def pytest_runtest_setup(item):
tags = list()
for marker in item.iter_markers(name="tag"):
for tag in marker.args:
tags.append(tag)
if tags:
cmd_tag = item.config.getoption("--tag")
if cmd_tag != "all" and cmd_tag not in tags:
pytest.skip("test requires tag in {!r}".format(tags))
def pytest_runtestloop(session):
if session.config.getoption('--dry-run'):
for item in session.items:
print(item.nodeid)
return True
def check_server_connection(request):
ip = request.config.getoption("--ip")
port = request.config.getoption("--port")
connected = True
if ip and (ip not in ['localhost', '127.0.0.1']):
try:
socket.getaddrinfo(ip, port, 0, 0, socket.IPPROTO_TCP)
except Exception as e:
print("Socket connnet failed: %s" % str(e))
connected = False
return connected
@pytest.fixture(scope="module")
def args(request):
ip = request.config.getoption("--ip")
service_name = request.config.getoption("--service")
port = request.config.getoption("--port")
url = "http://%s:%s/" % (ip, port)
client = MilvusClient(url)
args = {"ip": ip, "port": port, "service_name": service_name, "url": url, "client": client}
return args
@pytest.fixture(scope="function")
def client(request, args):
client = args["client"]
return client
@pytest.fixture(scope="function")
def collection(request, client):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
create_params = gen_default_fields()
try:
if not client.create_collection(collection_name, create_params):
pytest.exit(str(e))
except Exception as e:
pytest.exit(str(e))
def teardown():
collections = client.list_collections()
for item in collections:
client.drop_collection(item["collection_name"])
request.addfinalizer(teardown)
assert client.has_collection(collection_name)
return collection_name
# customised id
@pytest.fixture(scope="function")
def id_collection(request, client):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
try:
client.create_collection(collection_name, gen_default_fields(auto_id=False))
except Exception as e:
pytest.exit(str(e))
def teardown():
collections = client.list_collections()
for item in collections:
client.drop_collection(item["collection_name"])
request.addfinalizer(teardown)
assert client.has_collection(collection_name)
return collection_name
@pytest.fixture(scope="function")
def binary_collection(request, client):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
try:
client.create_collection(collection_name, gen_default_fields(binary=True))
except Exception as e:
pytest.exit(str(e))
def teardown():
collections = client.list_collections()
for item in collections:
client.drop_collection(item["collection_name"])
request.addfinalizer(teardown)
assert client.has_collection(collection_name)
return collection_name
# customised id
@pytest.fixture(scope="function")
def binary_id_collection(request, client):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
try:
client.create_collection(collection_name, gen_default_fields(auto_id=False, binary=True))
except Exception as e:
pytest.exit(str(e))
def teardown():
collections = client.list_collections()
for item in collections:
client.drop_collection(item["collection_name"])
request.addfinalizer(teardown)
assert client.has_collection(collection_name)
return collection_name
\ No newline at end of file
import utils
default_fields = utils.gen_default_fields()
default_binary_fields = utils.gen_binary_default_fields()
default_entity = utils.gen_entities(1)
default_raw_binary_vector, default_binary_entity = utils.gen_binary_entities(1)
default_entities = utils.gen_entities(utils.default_nb)
default_raw_binary_vectors, default_binary_entities = utils.gen_binary_entities(utils.default_nb)
#!/bin/bash
set -e
if [ "$1" = 'start' ]; then
tail -f /dev/null
fi
exec "$@"
\ No newline at end of file
[pytest]
log_format = [%(asctime)s-%(levelname)s-%(name)s]: %(message)s (%(filename)s:%(lineno)s)
log_date_format = %Y-%m-%d %H:%M:%S
log_cli = true
log_level = 20
timeout = 360
markers =
level: test level
serial
#level = 1
numpy>=1.18.0
pylint==2.5.0
pytest==4.5.0
pytest-timeout==1.3.3
pytest-repeat==0.8.0
allure-pytest==2.7.0
pytest-print==0.1.2
pytest-level==0.1.1
pytest-xdist==1.23.2
scikit-learn>=0.19.1
kubernetes==10.0.1
pymilvus-test>=0.4.5
\ No newline at end of file
astroid==2.2.5
atomicwrites==1.3.0
attrs==19.1.0
importlib-metadata==0.15
isort==4.3.20
lazy-object-proxy==1.4.1
mccabe==0.6.1
more-itertools==7.0.0
numpy==1.16.3
pluggy==0.12.0
py==1.8.0
pylint==2.5.0
pytest==4.5.0
pytest-timeout==1.3.3
pytest-repeat==0.8.0
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
pymilvus>=0.2.0
numpy>=1.18.0
pylint==2.5.0
pytest==4.5.0
pytest-timeout==1.3.3
pytest-repeat==0.8.0
allure-pytest==2.7.0
pytest-print==0.1.2
pytest-level==0.1.1
pytest-xdist==1.23.2
scikit-learn>=0.19.1
kubernetes==10.0.1
#/bin/bash
pytest . $@
\ No newline at end of file
import logging
import pytest
import pdb
from utils import *
__version__ = '0.11.0'
class TestPing:
def test_server_version(self, client):
'''
target: test get the server version
method: call the server_version method after connected
expected: version should be the milvus version
'''
res = client.system_cmd("version")
assert res == __version__
def test_server_status(self, client):
'''
target: test get the server status
method: call the server_status method after connected
expected: status returned should be ok
'''
msg = client.system_cmd("status")
assert msg
def test_server_cmd_with_params_version(self, client):
'''
target: test cmd: version
method: cmd = "version" ...
expected: when cmd = 'version', return version of server;
'''
cmd = "version"
msg = client.system_cmd(cmd)
logging.getLogger().info(msg)
assert msg == __version__
def test_server_cmd_with_params_others(self, client):
'''
target: test cmd: lalala
method: cmd = "lalala" ...
expected: when cmd = 'version', return version of server;
'''
cmd = "rm -rf test"
msg = client.system_cmd(cmd)
assert msg == default_unknown_cmd
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册