python locust-事件顺序

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")

  

原文地址:https://www.cnblogs.com/tallme/p/11188214.html