+ 增加后端接口测试脚本

This commit is contained in:
马琦钧 2021-06-24 13:36:40 +08:00
parent 11a02909ca
commit 3b84a4f720
1 changed files with 32 additions and 0 deletions

32
be/test.py Normal file
View File

@ -0,0 +1,32 @@
import requests
import json
import threading
headers = {'Content-Type': 'application/json'}
data = {"projectName":"demo5","fileName":"test11.txt","annoDetails":[{"name":"","type":"person1","start":5,"end":6,"isSmall":False}]}
test_times = 20
test_cnt = 0
err_cnt = 0
def create_load():
global test_times
global test_cnt
global err_cnt
result = requests.post('http://127.0.0.1:9060/v1/anno/create', data=json.dumps(data), headers=headers)
if result.json()['errMsg']:
err_cnt += 1
print('Catch Err:', result.json())
test_cnt += 1
if test_cnt == test_times:
if err_cnt == 0:
print('Test success!')
else:
print('Test failed!')
print('Start', test_times, 'test')
for i in range(test_times):
# 单线程测试
# create_load()
# 多线程测试
t = threading.Thread(target=create_load,args=())
t.start()