zoukankan      html  css  js  c++  java
  • python+locust+get/post接口性能测试

    #!/usr/local/bin/python3.7
    
    from locust import HttpLocust,TaskSet,task
    import gevent
    # 猴子补丁
    gevent.monkey.patch_all()
    import os
    import subprocess
    import json
    
    """
    @author:mozili
    @file:functiontest.py
    @time:2020/03/27
    """
    
    
    class UserBehavior(TaskSet):
        # 定义用户最先开始做的事情
        def on_start(self):
            pass
        
        def fun(self,response):
            if response.status_code != 200:
                print('返回异常')
                print("请求返回状态码:",response.status_code)
            elif response.status_code == 200:
                print('返回正常')
        @task(1)
        def download(self): 
            url = '/download?size=51457280'
            r = self.client.get(url=url)
            self.fun(r)
            
        @task(2)
        def upload(self):
            url = '/upload'
            params = {'size':30000000}
            r = self.client.post(url=url,params=params)
            self.fun(r)
        @task(3)
        def hello(self):
            url = '/hello'
            params = {'size':3000000}
            r = self.client.post(url=url,params=params)
            self.fun(r)
    class WebsiteUser(HttpLocust):
        task_set = UserBehavior
        min_wait = 3000
        max_wait = 6000
    
    if __name__ == '__main__':
        os.system('locust -f FunctionTest/functiontest.py --host=http://10.0.0.xxx:xxx')
        # 在命令行打开
        # subprocess.Popen('locust -f FunctionTest/functiontest.py',shell=True)






  • 相关阅读:
    理解Linux虚拟文件系统VFS
    Linux进程间通信(IPC)
    为 区域添加 Tag
    html 模板 swig 预编译插件 grunt-swig-precompile
    如何开发 Grunt 插件
    Web开发常见的漏洞
    CSS实现不固定宽度和高度的自动居中
    Sublime Text 前端插件推荐
    JavaScript 防止事件冒泡
    HTML标签篇
  • 原文地址:https://www.cnblogs.com/lxmtx/p/12580031.html
Copyright © 2011-2022 走看看