Answer the question
In order to leave comments, you need to log in
How to get worker ID in Locust (python)?
Good day! There was a need to write a couple of tests for loading the system in Locust, but suddenly there was a problem with the limitations of this very system.
The bottom line is this: I need to bind a specific Locust worker (flow) to a specific account. For example, thread #1 - user1, thread #2 - user2. That is, so that all actions in a single thread are performed strictly by one user. But neither in the documentation, nor anywhere else did I find how to get the ID of a particular thread executing the code, or even the number of threads at least (except from the command line via sys.argv)
Is there any kind of workaround?
Answer the question
In order to leave comments, you need to log in
I solved this problem in the following way. I created an additional class with the attributes I needed (ID, for example) and inherited it with a class that describes the behavior of the user's locust. After that, when creating a user, I assign him a unique ID, which is generated by a third-party function. It looks something like this:
class TestAttributes:
def __init__(self):
self.id = None
class UserBehavior(TaskSequence, TestAttributes):
def on_start(self):
self.id = generate_id()
self.client.post(url=my_url, data=my_body, headers=my_headers, name='Test request: %s' % self.id)
class UserBehavior(TaskSequence):
user_id = generate_id()
self.user_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question