Locust: How to create multiple task_set in http locust class?

Created on 7 Apr 2017  路  6Comments  路  Source: locustio/locust

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

Most helpful comment

@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.

All 6 comments

what error are you getting? please include the entire stacktrace

@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: )> failed with TypeError
[2017-04-07 14:57:31,619] HQSWL-C018024/ERROR/stderr: KeyboardInterrupt

I have tried another as well.

@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.

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

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

Addressed, closing

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannickXiong picture YannickXiong  路  3Comments

gboorse picture gboorse  路  3Comments

bgenchel picture bgenchel  路  3Comments

ShaolongHu picture ShaolongHu  路  3Comments

styk-tv picture styk-tv  路  3Comments