Skip to content Skip to sidebar Skip to footer

In Locust How To Get A Response From One Task And Pass It To Other Task

I have started using Locust to do performance test. I want to fire two post request to two different end points. But the second post request needs response of the first request. Ho

Solution 1:

You can call on_start(self) function which prepare data for you before passing to the task list. See example below:

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"

Post a Comment for "In Locust How To Get A Response From One Task And Pass It To Other Task"