【问题标题】:Locust: got 0 response status_code and None contentLocust:得到 0 响应 status_code 和无内容
【发布时间】:2013-06-26 10:05:26
【问题描述】:

我使用 Locust (http://locust.io) 编写了一个简单的负载测试。

现在我注意到,有时(使用更高的负载)我从 post call 得到的响应的 status_code 为 0 和 None 内容。 0状态码在Locust中不会自动识别为失败,所以我必须手动测试一下。

我的代码片段是这样的:

with self.client.get(path, catch_response=True) as response:
    if response.status_code != 200:
        response.failure(path + ": returned " + str(response.status_code))
    elif check not in response.content:
        response.failure(path + ": wrong response, missing '" + check + "'")

注意:check 是部分预期响应内容的变量。

问题是:这是预期的行为吗?这是 Locust(或 Python)的问题,还是测试应用程序的问题?

【问题讨论】:

    标签: python http locust


    【解决方案1】:

    来自蝗虫文档:http://docs.locust.io/en/latest/writing-a-locustfile.html

    安全模式

    HTTP 客户端配置为在安全模式下运行。这样做是因为任何由于连接错误、超时或类似情况而失败的请求都不会引发异常,而是返回一个空的虚拟响应对象。该请求将在 Locust 的统计信息中报告为失败。返回的 dummy Response 的 content 属性将设置为 None,其 status_code 将为 0。

    看起来服务器无法处理您蜂拥而至的所有请求,并且其中一些请求超时。

    【讨论】:

    • 啊,是的,谢谢。我错过了。所以看来,使用with self.client.get(path, catch_response=True) as response:我必须自己检查失败。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    相关资源
    最近更新 更多