性能测试-locust 基础模板

复制代码
from locust import HttpUser
from locust import TaskSet
from locust import task

class Demo(TaskSet):
    """继承   定义任务类"""
    def on_start(self):
        print("开始执行")

    @task
    def bai_du(self):

        url = 'https://new.czwlyk.com/login'
        data = {
            "acco": "xujh",
            "steg": "111111",
            "code": "string"
        }
        headers = {"Content-Type": "application/json"}
        with self.client.request(method='POST', url=url, json=data, headers=headers, name='login登录') as response:
            if response.status_code == 200:
                if response.json().get('code') == 200:
                    print('登录成功')
                else:
                    response.failure("登录失败")
            else:
                response.failure("登录失败")


class WebSitUser(HttpUser):

    """继承   定义用户类,访问用户"""
    tasks = [Demo]      # 指定任务类
    host = "http://127.0.0.1:8080/"  # 指定主机地址
    min_wait = 2000
    max_wait = 3000
    # 指定思考时间,3s到2s之内随机选取一个时间充当思考时间

在终端运行:
cmd终端直接执行:locust -f demo.py
 
复制代码

 

posted @   徐俊112  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示