In locust How to get a response from one task and pass it to other task

后端 未结 1 1716
心在旅途
心在旅途 2021-02-13 04:25

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.

相关标签:
1条回答
  • 2021-02-13 05:16

    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"
    
    0 讨论(0)
提交回复
热议问题