Skip to content

Commit 4e88723

Browse files
taskingaijcSimsonW
authored andcommitted
test: add test for async
1 parent 4a0c4ae commit 4e88723

26 files changed

+1201
-2517
lines changed

test/common/app_auth.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/common/logger.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,3 @@ def logger_success_info(http_code: str, http_status: str, data_status, res):
5656
def logger_error_info(http_code: str, http_status: str, data_status, res):
5757
logger_info_base(http_code, http_status, res)
5858
logger.info("data_status ==>> except_res:{}, real_res:【 {} 】".format(data_status, res.json()["error"]["code"]))
59-
60-
61-

test/common/utils.py

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
from typing import Dict, Any
2-
import asyncio
32
import random
43
import string
54
import pytest
65

7-
from test.common.logger import logger
8-
96

107
class ResponseWrapper:
118
def __init__(self, status: int, json_data: Dict):
@@ -27,17 +24,6 @@ def list_to_dict(data: list):
2724
return d
2825

2926

30-
def get_random_email():
31-
domain = ["163.com", "126.com", "yeah.net", "vip.163.com", "vip.126.com", "188.com", "vip.188.com", "qq.com",
32-
"gmail.com", "yahoo.com", "sina.com", "sina.cn", "sohu.com", "sogou.com", "outlook.com", "189.com",
33-
"wo.cn", "139.com", "ailiyun.com", "icloud.com", "tianya.cn", "renren.com", "tom.com"]
34-
username_length = random.randint(5, 10)
35-
username = ''.join(random.choices(string.ascii_lowercase, k=username_length))
36-
domain_name = random.choice(domain)
37-
email = username + "@" + domain_name
38-
return email
39-
40-
4127
def get_password():
4228
return ''.join(random.choices(string.ascii_letters, k=7))+str(random.randint(0, 9))
4329

@@ -103,92 +89,9 @@ def assume_chunk(res, chunk_dict: Dict[str, Any]):
10389
pytest.assume(len(res.json()["data"]) == res.json()["fetched_count"] == chunk_dict["top_k"])
10490

10591

106-
async def mq_execute_create_collection(n, func, *args, **kwargs):
107-
if n == 10:
108-
logger.info(func+"timeout")
109-
pytest.assume(False)
110-
else:
111-
from test.retrieval_service.collection import get_collection
112-
res = await get_collection(*args, **kwargs)
113-
if res.json()["data"]["status"] == "ready" and res.json()["data"]["num_records"] >= 0 and res.json()["data"]["num_chunks"] >= 0:
114-
return
115-
else:
116-
await asyncio.sleep(1)
117-
logger.info(f"collection status is {res.json()['data']['status']}")
118-
logger.info(f"collection num_records is {res.json()['data']['num_records']}")
119-
logger.info(f"collection num_chunks is {res.json()['data']['num_chunks']}")
120-
await mq_execute_create_collection(n+1, func, *args, **kwargs)
121-
122-
123-
async def mq_execute_delete_collection(n, func, *args, **kwargs):
124-
if n == 10:
125-
logger.info(func + "timeout")
126-
pytest.assume(False)
127-
else:
128-
from test.retrieval_service.collection import get_collection
129-
res = await get_collection(*args, **kwargs)
130-
if res.status_code == 404:
131-
logger.info(f"project[{args[0]}]collection[{args[1]}] is deleted")
132-
return
133-
else:
134-
await asyncio.sleep(1)
135-
await mq_execute_delete_collection(n+1, func, *args, **kwargs)
136-
137-
138-
async def mq_execute_create_record(n, func, *args, **kwargs):
139-
if n == 10:
140-
logger.info(func + "timeout")
141-
pytest.assume(False)
142-
else:
143-
from test.retrieval_service.record import get_record
144-
res = await get_record(*args, **kwargs)
145-
if res.json()["data"]["status"] == "ready" and res.json()["data"]["num_chunks"] >= 0:
146-
logger.info(f"project[{args[0]}]collection[{args[1]}]record[{args[2]}] status is ready")
147-
return
148-
elif res.json()["data"]["status"] == "partial" and res.json()["data"]["num_chunks"] >= 0:
149-
logger.info(f"project[{args[0]}]collection[{args[1]}]record[{args[2]}] is partial")
150-
return
151-
else:
152-
await asyncio.sleep(1)
153-
logger.info(f"record status is {res.json()['data']['status']}")
154-
logger.info(f"record num_chunks is {res.json()['data']['num_chunks']}")
155-
await mq_execute_create_record(n + 1, func, *args, **kwargs)
156-
157-
158-
async def mq_execute_delete_record(n, func, *args, **kwargs):
159-
if n == 10:
160-
logger.info(func + "timeout")
161-
pytest.assume(False)
162-
else:
163-
from test.retrieval_service.record import get_record
164-
res = await get_record(*args, **kwargs)
165-
if res.status_code == 404:
166-
logger.info(f"project[{args[0]}]collection[{args[1]}]record[{args[2]}] is deleted")
167-
return
168-
else:
169-
await asyncio.sleep(1)
170-
await mq_execute_delete_record(n + 1, func, *args, **kwargs)
171-
172-
173-
async def mq_execute_delete_project(n, func, *args, **kwargs):
174-
if n == 10:
175-
logger.info(func + "timeout")
176-
pytest.assume(False)
177-
else:
178-
from test.retrieval_service.collection import list_collections
179-
collections_res = await list_collections(*args, **kwargs)
180-
if collections_res.status_code == 400:
181-
return
182-
else:
183-
await asyncio.sleep(1)
184-
await mq_execute_delete_project(n + 1, func, *args, **kwargs)
185-
186-
18792
def get_random():
18893
return ''.join(random.choices(string.ascii_letters, k=7))+str(random.randint(0, 9))
18994

19095

19196
def get_project_id(i: int):
19297
return (get_random() for j in range(i))
193-
194-

test/config.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import os
1+
# your chat_model_id
22

3-
# text_model_id = os.getenv("text_model_id")
4-
# chat_model_id = os.getenv("chat_model_id")
5-
6-
# text_model_id = "fTfk462c"
73
chat_model_id = "KnnBZsjH"
4+
5+
# your text_model_id
6+
7+
text_model_id = "fTfk462c"
8+
9+
# need sleep time
10+
811
sleep_time = 1
9-
nums = (i+1 for i in range(10))
10-
text_model_id = "mF4PYMaR"
12+
13+
1114
# TASKINGAI_API_KEY = "tag4rNUwc7sYBjTjXtGNe6WbGNhI056C"

0 commit comments

Comments
 (0)