我正在使用Locust对一些API进行负载测试,下面是Locust文件(locastfile.py)的样子:
class MyTests(TaskSet):
def on_start(self):
print("Starting tests")
def get_something(self):
with self.client.get("some_baseuri" + "some_basepath", catch_response=True) as response:
print("Response code: {}".format(response.status_code))
print("Response body: {}".format(response.content))
@task(1)
def my_task(self):
self.get_something()
class WebsiteUser(HttpLocust):
task_set = MyTests
以下是我触发测试的方式:
locust -f locustfile.py --no-web --clients=1 --hatch-rate=10 --host=http://127.0.0.1 --num-request=2 --print-stats --only-summary
问题是,在日志中,
response.status_code
打印为200,但
response.content
正好是空的。当我使用Postman访问相同的API时,我在响应中看到了预期的正确响应主体。这看起来像是一个奇怪的问题,它阻止我调用另一个依赖于
get_something()
方法,因为其他API从
get\u something()
方法作为输入。