4

We are trying to achieve a user-scenatio based load testing which basically creates an order in one url and then we have to pass the order id in the next url to get the status of that order.

We are using locust sequential task for it. As we want it to run sequentially like first request -> second request -> third request. We are already getting the response data as expected but we are not able to send that variable data to the third task in order to display the status of the order.

import json
from locust import HttpLocust, TaskSet, task, TaskSequence, seq_task

class MyTaskSequence(TaskSequence):

    response_data = ""

    @seq_task(1)
    def index(self):
        print("--- First Task")
        response = self.client.get("/order/testing-06a5c/")
        print(response.status_code)

    @seq_task(2)
    def get_details(self):
        print("--- Second Task")
        response = self.client.post(return_data, headers={"authority": "staging.domain.com", "referer":"https://staging.domain.com/"})
        print(response.status_code)
        response_data = json.loads(response.text)
        print(response_data["details"]["claim_uri"])
        self.response_data

    def on_start(self):
        self.get_details()

    @seq_task(3)     
    def post_details(self):
        print(self.get_details())
        print("-- Third Task", self.response_data)
        #return_data = self.response_data["details"]["claim_uri"]
        #response = self.client.post(return_data, headers={"authority": "staging.domain.com", "referer":"https://staging.domain.com/"})
        #print(response.text)

class MyLocust(HttpLocust):
    task_set = MyTaskSequence
    min_wait = 5000
    max_wait = 15000
    host = 'https://staging.domain.com'

Output:

[2018-11-19 19:24:19,784] system.local/INFO/stdout:
[2018-11-19 19:24:19,784] system.local/INFO/stdout: --- First Task
[2018-11-19 19:24:19,785] system.local/INFO/stdout:
[2018-11-19 19:24:20,235] system.local/INFO/stdout: 200
[2018-11-19 19:24:20,235] system.local/INFO/stdout:
[2018-11-19 19:24:29,372] system.local/INFO/stdout: --- Second Task
[2018-11-19 19:24:29,373] system.local/INFO/stdout:
[2018-11-19 19:24:29,653] system.local/INFO/stdout: 200
[2018-11-19 19:24:29,654] system.local/INFO/stdout:
[2018-11-19 19:24:29,654] system.local/INFO/stdout: /payment/initiate/claim/bc6d5024-f608-41af-8e78-191798c31a69/
[2018-11-19 19:24:29,654] system.local/INFO/stdout:
[2018-11-19 19:24:37,089] system.local/INFO/stdout: --- Second Task
[2018-11-19 19:24:37,089] system.local/INFO/stdout:
[2018-11-19 19:24:37,367] system.local/INFO/stdout: 200
[2018-11-19 19:24:37,367] system.local/INFO/stdout:
[2018-11-19 19:24:37,367] system.local/INFO/stdout: /payment/initiate/claim/72217a35-01fc-488e-885e-aea81a57a463/
[2018-11-19 19:24:37,368] system.local/INFO/stdout:
[2018-11-19 19:24:37,368] system.local/INFO/stdout: None
[2018-11-19 19:24:37,368] system.local/INFO/stdout:
[2018-11-19 19:24:37,368] system.local/INFO/stdout: ('-- Third Task', '')
[2018-11-19 19:24:37,368] system.local/INFO/stdout:
^C[2018-11-19 19:24:40,598] system.local/ERROR/stderr: KeyboardInterrupt

We wanted to pass response_data["details"]["claim_uri"] variable to @seq_task(3). So that we can form a dynamic target which will be domain.com/response_data["details"]["claim_uri"]. This variable will be of string type and have to pass separately everytime the third task invokes.

We tried this method but getting None in the output.

Is there anything which is missing out?

mohit
  • 2,325
  • 23
  • 48

1 Answers1

6

The issue was with the variable response data. The scope of the variable was local while calling it without self.

The below code works.

@seq_task(2)
    def get_details(self):
        <-- function data -->
        self.response_data = json.loads(response.text)
Federico Baù
  • 6,013
  • 5
  • 30
  • 38
mohit
  • 2,325
  • 23
  • 48