批量数据请求接口

以下是一个简单的demo模型,具体的注册接口替换过去就可以了

# 保存为 locustfile4.py
#  coding=utf-8
from locust import HttpLocust, TaskSet, task
import queue class test_taskset(TaskSet):  @task def register(self): try: tel = self.locust.telqueue.get() # 获取队列里的数据 print(tel) except queue.Empty: # 队列取空后,直接退出 print("no data exist") exit(0) print("当前注册手机号:%s" % tel) # body = { # "username": tel, # "psd": "123456", # } # self.client.post("/register", data=body) # POST方法发送请求 class test_run(HttpLocust): host = 'http://192.168.1.xxx:80' task_set = test_taskset # 生成测试手机号 teldatas = [str(13812120000+i) for i in range(100)] # 添加到队列 telqueue = queue.Queue() for i in teldatas: telqueue.put_nowait(i) if __name__ == "__main__": import os os.system("locust -f locustfile4.py")

猜你喜欢

转载自www.cnblogs.com/yaohu/p/10305502.html