• Locust HTTP client


    Http client 默认是以安全模式运行的,任何由于连接错误、超时或者类似错误引起的异常,都会返回一个空的Response对象,这个请求将会再locust统计中标记为failure,返回的虚拟对象Response’content属性将会被置为空,status_code为0。一般不用再使用try...exception处理异常。

    默认情况下,返回2xx的状态码的都会标记为success,之外的情况都会被标记为failure,如果想手动改变这种情况,需要手动控制。

     

    实例:如果返回的内容不包含Success文本,则标记为失败;如果返回码不是404失败

    class UserTask1(TaskSet):
        @task
        def task(self):
            with self.client.get("/", catch_response=True) as response:
                if response.status_code == 400:
                    response.success()
                else:
                    response.failure(response)
    
    class UserTask2(TaskSet):
        @task
        def task(self):
            with self.client.get("/belle-ls/", catch_response=True, verify=False) as response:
                if response.content != b"Success":
                    response.failure("Failed")

     

    请求时参数替换

    # Statistics for these requests will be grouped under: /blog/?id=[id]
    for i in range(10):
        client.get("/blog?id=%i" % i, name="/blog?id=[id]")

     

  • 相关阅读:
    10、xsl中import用法
    09、xsl中输出对应的列和值
    08、xsl中操作子节点带循环输出
    07、xsl中操作子节点
    06、xsl中choose进行多条件选择
    05、xsl中IF的用法
    04、xsl中对字段进行排序
    03、xsl中添加筛选条件
    02、xsl的for循环输出
    01、xsl样式表用网页输出
  • 原文地址:https://www.cnblogs.com/belle-ls/p/10491590.html
Copyright © 2020-2023  润新知