from locust import HttpUser, task, run_single_user
from locust.exception import StopUser
class User1(HttpUser):
host = "http://localhost"
@task
def hello_world(self):
with self.client.get("/hello1", catch_response=True) as resp:
pass
raise StopUser()
class User2(HttpUser):
host = "http://localhost"
@task
def hello_world(self):
with self.client.get("/hello2", catch_response=True) as resp:
pass
raise StopUser()
if __name__ == "__main__":
print("running User1")
run_single_user(User1)
print("running User2")
run_single_user(User2)
print("done!")
转载于:https://github.com/locustio/locust/blob/master/examples/debugging_advanced.py
本文介绍了如何使用Locust库创建两个用户类(User1和User2),分别执行GET请求并触发StopUser异常来停止任务执行。通过实例展示了如何在主函数中运行这两个用户类。这是关于 Locust调试实践的基础示例。
672

被折叠的 条评论
为什么被折叠?



