Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass custom parameters to a locust test class?

Tags:

I'm currently passing custom parameters to my load test using environment variables. For example, my test class looks like this:

from locust import HttpLocust, TaskSet, task import os  class UserBehavior(TaskSet):      @task(1)     def login(self):         test_dir = os.environ['BASE_DIR']         auth=tuple(open(test_dir + '/PASSWORD').read().rstrip().split(':'))          self.client.request(            'GET',            '/myendpoint',            auth=auth         )     class WebsiteUser(HttpLocust):     task_set = UserBehavior 

Then I'm running my test with:

locust -H https://myserver --no-web --clients=500 --hatch-rate=500 --num-request=15000 --print-stats --only-summary 

Is there a more locust way that I can pass custom parameters to the locust command line application?

like image 425
Chris Snow Avatar asked Mar 09 '15 20:03

Chris Snow


People also ask

What is HttpUser in Locust?

HttpUser classThis class creates a client attribute on instantiation which is an HTTP client with support for keeping a user session between requests. abstract = True. If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test.

What is Wait_time in Locust?

The wait_time attribute It's used to determine for how long a simulated user will wait between executing tasks. Locust comes with a few built in functions that return a few common wait_time methods. The most common one is between .

How do you write a locust test?

How to run a load test in Locust. The key –host http://localhost:3000 specifies the host on which Locust should be run (the corresponding field is filled in by default, but this value can be changed). Specify the values: in our example, Number of users = 10 and Spawn rate = 2. Next, use Start swarming to run the test.


1 Answers

You could use like env <parameter>=<value> locust <options> and use <parameter> inside the locust script to use its value

E.g., env IP_ADDRESS=100.0.1.1 locust -f locust-file.py --no-web --clients=5 --hatch-rate=1 --num-request=500 and use IP_ADDRESS inside the locust script to access its value which is 100.0.1.1 in this case.

like image 55
neonidian Avatar answered Sep 20 '22 20:09

neonidian