Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique user id per locust #476

Closed
nickboucart opened this issue Sep 12, 2016 · 6 comments
Closed

Unique user id per locust #476

nickboucart opened this issue Sep 12, 2016 · 6 comments

Comments

@nickboucart
Copy link

Hello,

I'm trying to test a scenario where each user has her own unique user id (basically uuid.uuid4()).

I implemented an on_start method on my TaskSet:

    def on_start(self):
        self.locust.userId = str(uuid.uuid4())

When I run my scenario with say 5 users, I only get requests for 5 different users (i.e. 5 different uuid's). It seems that locust "reuses" these TaskSets, rather than instantiating a new one each time a locust has done its tasks.

Is there a way to implement my scenario? Am I missing something?

Thanks!

@cgoldberg
Copy link
Member

When I run my scenario with say 5 users,
I only get requests for 5 different users

on_start is called once, and the TaskSet will continuously select tasks to execute.

@nickboucart
Copy link
Author

Thanks for your reply. That's exactly the behaviour I see. Any tips on how I could implement the scenario I describe above, if possible at all?
Thanks!
Nick

@cgoldberg
Copy link
Member

Any tips on how I could implement the scenario I describe above

You would have to modify locust to meet your needs. on_start is called in core.py. See the run() method in the TaskSet class..

@lyenliang
Copy link

You should write self.locust.userId = str(uuid.uuid4()) inside your task. i.e.

def on_start(self):
    # remove self.locust.userId = str(uuid.uuid4())
    # ...

@task(1)
def doSomething(self):
    self.locust.userId = str(uuid.uuid4())
    # ...

@ghost
Copy link

ghost commented Feb 14, 2017

I had exactly the same problem.
In the end, I came up with a solution of implementing a FSM to make sure that at first, the user ID is selected/generated and that it is being reused for the other steps. The weight might become worthless, haven't really tested/used that.

@aldenpeterson-wf
Copy link
Contributor

Addressed, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants