1
1
from typing import Dict , Any
2
- import asyncio
3
2
import random
4
3
import string
5
4
import pytest
6
5
7
- from test .common .logger import logger
8
-
9
6
10
7
class ResponseWrapper :
11
8
def __init__ (self , status : int , json_data : Dict ):
@@ -27,17 +24,6 @@ def list_to_dict(data: list):
27
24
return d
28
25
29
26
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
-
41
27
def get_password ():
42
28
return '' .join (random .choices (string .ascii_letters , k = 7 ))+ str (random .randint (0 , 9 ))
43
29
@@ -103,92 +89,9 @@ def assume_chunk(res, chunk_dict: Dict[str, Any]):
103
89
pytest .assume (len (res .json ()["data" ]) == res .json ()["fetched_count" ] == chunk_dict ["top_k" ])
104
90
105
91
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
-
187
92
def get_random ():
188
93
return '' .join (random .choices (string .ascii_letters , k = 7 ))+ str (random .randint (0 , 9 ))
189
94
190
95
191
96
def get_project_id (i : int ):
192
97
return (get_random () for j in range (i ))
193
-
194
-
0 commit comments