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")
     
  • 相关阅读:
    Study Plan The TwentySecond Day
    Study Plan The Nineteenth Day
    Study Plan The TwentySeventh Day
    Study Plan The Twentieth Day
    Study Plan The TwentyFirst Day
    python实现进程的三种方式及其区别
    yum makecache
    JSONPath 表达式的使用
    oracle执行cmd的实现方法
    php daodb插入、更新与删除数据
  • 原文地址:https://www.cnblogs.com/yaohu/p/10305320.html
Copyright © 2011-2022 走看看