首页 > 其他 > 详细

批量数据请求接口

时间:2019-01-22 19:28:03      阅读:212      评论:0      收藏:0      [点我收藏+]

以下是一个简单的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")

批量数据请求接口

原文:https://www.cnblogs.com/yaohu/p/10305502.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!