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?
locust
add a comment |
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?
locust
add a comment |
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?
locust
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
locust
edited Nov 19 at 14:17
asked Nov 19 at 14:09
Mohit Kumar
576420
576420
add a comment |
add a comment |
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)
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered Nov 20 at 6:54
Mohit Kumar
576420
576420
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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