zoukankan      html  css  js  c++  java
  • locust基本使用

    from locust import HttpLocust, TaskSet, task
    import os, json


    # 性能测试任务类 TaskSet.
    class UserBehavior(TaskSet):
    # 只运行一次的方法
    @task
    def on_start(self):
    pass

    # 任务
    @task
    def send_api(self):

    request_url = "/eosCabinet/xxxxxxxxxeryForSgs/" # 待测试的路径
    request_header = {
    "Content-Type": "application/json",
    "stationCode": "8xxx001S"
    }

    request_json = {
    "stationCode": "8xxx01S"
    }
    # body = json.dumps(request_json)
    resp = self.client.post(url=request_url, headers=request_header, json=request_json, catch_response=True)
    resp.encoding = 'utf-8'
    if resp.status_code != 200:
    resp.success() # 统计结果用
    elif resp.status_code == 200:
    resp.failure("tishi")

    # # 这里可以编写自己需要校验的返回内容
    # text = json.loads(response.text)["text"]
    # if text["tagKey"] == 25:
    # print("校验成功")
    # print(json.dumps(text, encoding="UTF-8", ensure_ascii=False))


    # 性能测试配置
    class UserLocust(HttpLocust):
    # weight = 3
    task_set = UserBehavior
    host = "http://sgsxxxxx.cn:1080"
    # 思考时间
    min_wait = 1000
    max_wait = 5000
    # locust - f locustfile.py --host=http://192.168.x.xx:80 --no-web --csv=example - c1 - r1 - t10s
    # UI模式:localhost:8089;后台运行:c-用户数,r-多少秒内,t-运行时间可以指定单位时分秒:h-m-s
    # 主:locust - f locustfile.py --host=http://192.168.x.01:80 --master
    # 从:locust - f locustfile.py --host=http://192.168.x.02:81 --slave --master-host=http://192.168.x.01:80
    # 从:locust - f locustfile.py --host=http://192.168.x.03:82 --slave --master-host=http://192.168.x.01:80


    if __name__ == "__main__":
    os.system("locust -f locust_test.py")
     
  • 相关阅读:
    SQL Server SQLHelper帮助类
    Winform 常用的方法
    SQL Server 插入含有中文字符串出现乱码现象的解决办法
    ComboBox 中 DisplayMember 和 ValueMember 都是具体干什么的?
    HTML常用标签属性使用
    虚拟机安装windows server 2012 R2
    VS2017生成带图标的QT项目方法
    QSS 记录
    QT qss资源文件与代码分离
    pgsql 服务遇见的问题记录
  • 原文地址:https://www.cnblogs.com/yaohu/p/10305320.html
Copyright © 2011-2022 走看看