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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With