蝗虫:获得0响应status_code和无内容

obe*_*ker 6 python http locust

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

现在我注意到有时候(使用更高的负载)我从post调用得到的响应有一个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 + "'")
Run Code Online (Sandbox Code Playgroud)

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

问题是:这是预期的行为吗?这是Locust(或Python)的问题还是在测试应用程序中出现故障?

小智 9

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

安全模式

HTTP客户端配置为在safe_mode中运行.这样做的是,由于连接错误,超时或类似原因而失败的任何请求都不会引发异常,而是返回一个空的虚拟Response对象.请求将在Locust的统计信息中报告为失败.返回的虚拟Response的content属性将设置为None,并且status_code将为0.

它看起来像服务器无法处理你所拥有的所有请求,其中一些是超时.

  • 啊,是的,谢谢.我错过了.所以看来,使用`with self.client.get(path,catch_response = True)作为回应:`我必须自己检查失败. (2认同)