Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create multiple task_set in http locust class? #573

Closed
nrbalajimca opened this issue Apr 7, 2017 · 6 comments
Closed

How to create multiple task_set in http locust class? #573

nrbalajimca opened this issue Apr 7, 2017 · 6 comments

Comments

@nrbalajimca
Copy link

I have tried to create a multipls task_set under locust class. While creating am getting error message. Pls assist me. Eg. below

class ApiClient(HttpLocust):
task_set = ApiClientBehavior
task_set = ApiClientBehavior1

Also i have tried below way also,

class ApiClient(HttpLocust):
# taskset is just a POPO
task_set = ApiClientBehavior
task_set1 = ApiClientBehavior1

@cgoldberg
Copy link
Member

what error are you getting? please include the entire stacktrace

@nrbalajimca
Copy link
Author

nrbalajimca commented Apr 7, 2017

@cgoldberg
I'm sorry for the above code, am not getting any error message. It only execute the tas_set and it is not executing task_set1. Please find my entire code below.

from locust import TaskSet, task, HttpLocust
import json

class ApiClientBehavior(TaskSet):

headers = {'content-type': 'application/json'}
# device_name = "sur01.whitebear.mn.minn.comcast.net"
key = "30661f00d312221ddf232e5ffc88870f468aba63"

@task(1)
def get_response(self):
    response = self.client.get("/v1/v1/docs/sm001482886-5363f0288gebo-wholesaleethernet", headers = self.headers, name='A 200 Status')
    if response.status_code == 200:
        print "Get response status code:", response.status_code
        # print "Response content:", response.content
    else:
        response.failure("Got wrong response code")

class ApiClientBehavior1(TaskSet):

@task(2)
def post_response(self):
    payload = {"names": ["sur01.perry.fl.tallah.comcast.net", "sur01.arvada.co.denver.comcast.net", "AR151.000195"]}
    response = self.client.post("/v1/elements?key=30661f00d312221ddf232e5ffc88870f468aba63", data=json.dumps(payload), headers = self.headers, name='A 200 Status')
    if response.status_code == 200:
        print "Post response status code:", response.status_code
        # print "Response content:", response.content
    else:
        response.failure("Got wrong response code")

class ApiClient(HttpLocust):

task_set = ApiClientBehavior
task_set = ApiClientBehavior1
min_wait = 1000
max_wait = 5000
# host = "http://cmaas-element-api-qa.cm.comcast.net"

If i do the below method:
class ApiClient(HttpLocust):
# taskset is just a POPO
task_set = ApiClientBehavior, ApiClientBehavior1

I'm getting this error messge.
[2017-04-07 14:57:31,526] HQSWL-C018024/ERROR/stderr: self.task_set(self).run()
[2017-04-07 14:57:31,528] HQSWL-C018024/ERROR/stderr: TypeError: 'tuple' object is not callable
[2017-04-07 14:57:31,528] HQSWL-C018024/ERROR/stderr: <Greenlet at 0x62764e0: start_locust(<class 'locustfile.ApiClient'>)> failed with TypeError
[2017-04-07 14:57:31,619] HQSWL-C018024/ERROR/stderr: KeyboardInterrupt

I have tried another as well.

@prince-mishra
Copy link

prince-mishra commented May 24, 2017

@nrbalajimca If all you want is to be able to run locust for multiple task_sets, just add multiple Client classes in your locustfile, each using its separate task_set

class ClientOne(HttpLocust):
    task_set = TaskSetOne

class ClientTwo(HttpLocust):
    task_set = TaskSetTwo

locust will load both Client classes when run.

@RazmikMkrtchyan
Copy link

RazmikMkrtchyan commented May 25, 2017

@prince-mishra ,and how to run these clients with a single command?

This way?
locust -f xxx.py --host=xxx ClientOne ClientTwo ?

@aldenpeterson-wf
Copy link
Contributor

Addressed, closing

@rahul-jain101
Copy link

Is it possible for running multiple task-sets from using what was suggested above (making multiple clients) that we can have multiple graphs be shown? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants