test:fix retry for network error (#32804)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
pull/32808/head
zhuwenxing 2024-05-07 14:01:29 +08:00 committed by GitHub
parent e1eb03ad0d
commit 29f3cb692b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 7 deletions

View File

@ -3,7 +3,8 @@ import requests
import time
import uuid
from utils.util_log import test_log as logger
from tenacity import retry, retry_if_exception_type, stop_after_attempt
from requests.exceptions import ConnectionError
def logger_request_response(response, url, tt, headers, data, str_data, str_response, method):
if len(data) > 2000:
@ -42,6 +43,7 @@ class Requests:
}
return headers
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def post(self, url, headers=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -53,6 +55,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "post")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def get(self, url, headers=None, params=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -67,6 +70,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "get")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def put(self, url, headers=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -78,6 +82,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "put")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def delete(self, url, headers=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)

View File

@ -20,3 +20,4 @@ Faker==19.2.0
pymilvus==2.4.0rc19
scikit-learn~=1.1.3
pytest-xdist==2.5.0
tenacity==8.1.0

View File

@ -5,7 +5,10 @@ import uuid
from utils.util_log import test_log as logger
from minio import Minio
from minio.error import S3Error
from minio.commonconfig import REPLACE, CopySource
from minio.commonconfig import CopySource
from tenacity import retry, retry_if_exception_type, stop_after_attempt
from requests.exceptions import ConnectionError
def logger_request_response(response, url, tt, headers, data, str_data, str_response, method):
if len(data) > 2000:
@ -45,6 +48,9 @@ class Requests:
}
return headers
# retry when request failed caused by network or server error
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def post(self, url, headers=None, data=None, params=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -56,6 +62,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "post")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def get(self, url, headers=None, params=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -70,6 +77,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "get")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def put(self, url, headers=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)
@ -81,6 +89,7 @@ class Requests:
logger_request_response(response, url, tt, headers, data, str_data, str_response, "put")
return response
@retry(retry=retry_if_exception_type(ConnectionError), stop=stop_after_attempt(3))
def delete(self, url, headers=None, data=None):
headers = headers if headers is not None else self.update_headers()
data = json.dumps(data)

View File

@ -10,7 +10,7 @@ pymilvus==2.4.0rc39
scikit-learn~=1.1.3
pytest-xdist==2.5.0
minio==7.1.14
tenacity==8.1.0
# for bf16 datatype
jax==0.4.13
jaxlib==0.4.13

View File

@ -72,10 +72,10 @@ cd ${ROOT}/tests/restful_client
if [[ -n "${TEST_TIMEOUT:-}" ]]; then
timeout "${TEST_TIMEOUT}" pytest --reruns 3 --reruns-delay 1 testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} -v -x -m L0 -n 6 --timeout 180\
timeout "${TEST_TIMEOUT}" pytest testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} -v -x -m L0 -n 6 --timeout 180\
--html=${CI_LOG_PATH}/report_restful.html --self-contained-html
else
pytest --reruns 3 --reruns-delay 1 testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} -v -x -m L0 -n 6 --timeout 180\
pytest testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} -v -x -m L0 -n 6 --timeout 180\
--html=${CI_LOG_PATH}/report_restful.html --self-contained-html
fi
@ -84,10 +84,10 @@ cd ${ROOT}/tests/restful_client_v2
if [[ -n "${TEST_TIMEOUT:-}" ]]; then
timeout "${TEST_TIMEOUT}" pytest --reruns 3 --reruns-delay 1 testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} --minio_host ${MINIO_SERVICE_NAME} -v -x -m L0 -n 6 --timeout 180\
timeout "${TEST_TIMEOUT}" pytest testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} --minio_host ${MINIO_SERVICE_NAME} -v -x -m L0 -n 6 --timeout 180\
--html=${CI_LOG_PATH}/report_restful.html --self-contained-html
else
pytest --reruns 3 --reruns-delay 1 testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} --minio_host ${MINIO_SERVICE_NAME} -v -x -m L0 -n 6 --timeout 180\
pytest testcases --endpoint http://${MILVUS_SERVICE_NAME}:${MILVUS_SERVICE_PORT} --minio_host ${MINIO_SERVICE_NAME} -v -x -m L0 -n 6 --timeout 180\
--html=${CI_LOG_PATH}/report_restful.html --self-contained-html
fi