我已经开始使用 Locust 进行性能测试。我想向两个不同的端点发出两个发布请求。但是第二个 post 请求需要第一个请求的响应。如何以方便的方式做到这一点。我已经尝试过如下但不工作。
from locust import HttpLocust, TaskSet, task
class GetDeliveryDateTasks(TaskSet):
request_list = []
@task
def get_estimated_delivery_date(self):
self.client.headers['Content-Type'] = "application/json"
response = self.client.post("/api/v1/estimated-delivery-date/", json=
{
"xx": "yy"
}
)
json_response_dict = response.json()
request_id = json_response_dict['requestId']
self.request_list.append(request_id)
@task
def store_estimated_delivery_date(self):
self.client.headers['Content-Type'] = "application/json"
response = self.client.post("/api/v1/estimated-delivery-date/" + str(self.request_list.pop(0)) + "/assign-order?orderId=1")
class EDDApiUser(HttpLocust):
task_set = GetDeliveryDateTasks
min_wait = 1000
max_wait = 1000
host = "http://localhost:8080"