ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python locust-事件顺序

2019-07-15 13:02:13  阅读:344  来源: 互联网

标签:顺序 python locust stop teardown TaskSet print def


from  locust import HttpLocust,TaskSet,task
'''
点击STOP,会停止测试,并调用所有当前执行的TaskSet的on_stop,但不会调用teardown函数
ctrl +c,表示停止locust运行,此时会调用TaskSet teardown # 停止locust运行时执行,Locust teardown  # 停止locust运行时执行,(而不会调用TaskSet的on_stop,点击STOP,会停止测试,并调用所有当前执行的TaskSet的on_stop,但不会调用teardown函数)

stop_timeout:Locust停止的秒数,如果为None,将不停止一直执行任务,单位为s秒
-H:指定测试的主机地址(注:会覆盖Locust类指定的主机地址)
-f:指定测试脚本地址(注:脚本中必须包含一个Locust的衍生类)
--no-web:不启动web网页,而是直接开始运行测试,需提供属性-c和-r
-c:并发的用户数,与--no-web一起使用
-r:每秒启动的用户数,与--no-web一起使用
-t:运行时间(单位:秒),与--no-web一起使用
-L:日志级别,默认为INFO
调试命令:locust -f **.py --no-web -c 1 -t 1
运行命令:locust -f **.py

Locust setup  # 第一次启动Locust的时候执行
TaskSet setup       # 第一次实例化任务集时执行
TaskSet on_start  # 每一次开始一个任务时执行
TaskSet tasks…
TaskSet on_stop   # 点击页面stop时,当前所有在执行中的TaskSet执行
TaskSet teardown # 停止locust运行时执行
Locust teardown  # 停止locust运行时执行
'''
class mytaskset(TaskSet):
    def setup(self):
        print("TaskSet setup")
    def on_start(self):
        print("TaskSet on_start")

    @task(1)
    def one(self):
        print("任务1")
    @task(1)
    def two(self):
        print("任务2")
    def on_stop(self):
        print("TaskSet stop")
    def teardown(self):
        print("TaskSet teardown")
class websitUser(HttpLocust):
    weight = 1
    task_set = mytaskset
    host = "http://www.baidu.com"
    min_wait = 5000
    max_wait = 6000
    stop_timeout = 10
    def setup(self):
        print("locust set_up")
    def teardown(self):
        print("locust teardown")

  

标签:顺序,python,locust,stop,teardown,TaskSet,print,def
来源: https://www.cnblogs.com/tallme/p/11188214.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有