locust官方文档-debugging_advanced.py

本文介绍了如何使用Locust库创建两个用户类(User1和User2),分别执行GET请求并触发StopUser异常来停止任务执行。通过实例展示了如何在主函数中运行这两个用户类。这是关于 Locust调试实践的基础示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值