I'm trying to resolve 2 issues, and check the performance of my API.
Now, I have a file with a few million records (1 line, 1 record), and I need to fire all of them to my API. Loading the whole file in memory could work, even though I'd rather load batches of it. (That's 1 problem)
Second, I need to send X requests in and each request needs to have a different test data due to data being coordinates, and path recording (e.g. similar to strava when you are tracking a ride).
I have tried reading file in chunks, but not sure how to pass the data then to the method. Tried to loop within the method, but, that failed as well as Locust execute task automagically.
I cannot find anywhere in the documentation how to vary the data.
My idea was - read 1000 lines from file. Perform 1 request for each 1000 lines. Read next 1000 lines...
And do that as long as there are lines in the file.
I have this:
from locust import HttpUser, task, between
test_data_filename = '/Users/i/IdeaProjects/TestIntelliJ/test10.txt'
#loading test data set from .txt file - trying to read here in chunks, but I need single line from a chunk
with open(test_data_filename) as f:
test_data = f.readlines(100)
class HtpAPIUser(HttpUser):
host = 'myserver'
wait_time = between(3,5)
i = 0
# Was thinking of running here the task, but not sure how to do it?
for line in test_data:
test_data_line = line
@task()
# Thought of passing different test data line into the method, but not sure is that the way?
def tele_endpoint(self, test_data_line):
headers = {'Content-Type': 'application/xml'}
response = self.client.post('/push/data/points', data=test_data_line, headers=headers, verify=False)
print(response)