0

Referring to my locusfile.py below:

from locust import HttpLocust, TaskSet, between, task
import csv

class UserBehavior(TaskSet):
    @task(1)
    def index(l):
        with open ('topURL.csv') as csvfile:
            readCSV = csv.reader(csvfile, delimiter=',')
            for row in readCSV:
                l.client.get("%s" % (row[0]))

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    wait_time = between(5.0, 9.0)

When I execute this script, Locust was able to run without any error. However, it'll loop through each row and load test only the latest URL. As it reads the next URL, the previous URL is no longer being load tested. What I want instead is for Locust to load test more and more URLs concurrently as it reads row by row from the CSV.

Edit
I managed to achieve partial concurrency by setting wait_time = between(0.0, 0.0)

Kelvin Low
  • 678
  • 1
  • 10
  • 23

2 Answers2

0

Try filling an array with your csv data at setup and choosing randomly from it. Like

    def fill_array():
        with open('topURL.csv') as csvfile:
        readCSV = csv.reader(csvfile, delimiter=',')
        for row in readCSV:
            urls.append(row[0])

then

    @task(1)
    def index(l):
        l.client.get("%s" % (random.choice(urls)))

more info at setup: https://docs.locust.io/en/stable/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop

0

You could try something like:

global USER_CREDENTIALS
USER_CREDENTIALS = list(readCSV)

once done you will be able to refer each line for each virtual user/iteration

References:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133