Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic GET parameter in locust

Tags:

python

locust

from locust import HttpLocust, TaskSet, task
import random

ids = [101, 102, 103, 104, 105, 106, 107, 108, 109, 110]


class TestAPITaskSet(TaskSet):

    @task(1)
    def test_get_id(self):
        id = random.choice(ids)
        self.client.get("/test-api/id/" + str(id), name="/id/[id]")


class TestAPILocust(HttpLocust):
    task_set = TestAPITaskSet
    min_wait = 0
    max_wait = 1000

Is this good or is there any other better locust-native approach if I want to pick ids randomly from the list?

like image 422
Dev Avatar asked Dec 14 '25 14:12

Dev


1 Answers

There is no better locust-native approach, you code looks very reasonable!

If your list is starting to get very long and you are ok with picking sequentially from the list, you could have a look at CSVReader from locust-plugins: https://github.com/SvenskaSpel/locust-plugins/blob/master/examples/csvreader.py

like image 198
Cyberwiz Avatar answered Dec 17 '25 09:12

Cyberwiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!