Python 在Hocust中,如何从一个任务获得响应并将其传递给另一个任务
我已经开始使用蝗虫做性能测试。 我想将两个post请求发送到两个不同的端点。但是第二个post请求需要第一个请求的响应。如何以方便的方式进行此操作。我试过像下面这样,但没有工作Python 在Hocust中,如何从一个任务获得响应并将其传递给另一个任务,python,locust,Python,Locust,我已经开始使用蝗虫做性能测试。 我想将两个post请求发送到两个不同的端点。但是第二个post请求需要第一个请求的响应。如何以方便的方式进行此操作。我试过像下面这样,但没有工作 from locust import HttpLocust, TaskSet, task class GetDeliveryDateTasks(TaskSet): request_list = [] @task def get_estimated_delivery_date(self):
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"
您可以在启动时调用
(self)
函数,在传递到任务
列表之前为您准备数据。见下例:
from locust import HttpLocust, TaskSet, task
class GetDeliveryDateTasks(TaskSet):
request_list = []
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)
def on_start(self):
self.get_estimated_delivery_date()
@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"