Issue while passing data from one task function to another in locust with sequential task one by one











up vote
0
down vote

favorite












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?










share|improve this question




























    up vote
    0
    down vote

    favorite












    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?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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?










      share|improve this question















      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?







      locust






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 14:17

























      asked Nov 19 at 14:09









      Mohit Kumar

      576420




      576420
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          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)





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376427%2fissue-while-passing-data-from-one-task-function-to-another-in-locust-with-sequen%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            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)





            share|improve this answer

























              up vote
              0
              down vote













              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)





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                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)





                share|improve this answer












                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)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 6:54









                Mohit Kumar

                576420




                576420






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376427%2fissue-while-passing-data-from-one-task-function-to-another-in-locust-with-sequen%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?