0

community.

I need users created by different workers not to be duplicated. I.e. if worker_1 create user fake1 and run task for this user, worker_2 must not to be able create user fake1.

Currently it works only in standalone mode.

credentials = [ (f"fake{i}", 'password') for i in range(100) ]

class MobileUser(HttpUser):
    tasks = [RealTimeTask]
    wait_time = constant_pacing(1)

    def __init__(self, parent):
        super().__init__(parent)

        if len(credentials) > 0:
            shuffle(credentials)
            self.username, self.password = credentials.pop()
Vitali
  • 1
  • 1

1 Answers1

0

Not really. Slaves are blissfully unaware of each other.

I think your best options is to set an env var at worker start time:

WORKER_ID=1 locust --worker ...

(and then insert os.env['WORKER_ID'] into your user names to make them unique)

Every worker does have a unique id (accessible from a task using self.environment.runner.client_id), but they are not ordered (they contain hostname + a UUID), so I dont know if that really helps you.

Another option might be to use hostname + process id as an identifier.

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40
  • It is a pity. I know I can get the worker ID from `environment.runner.client_id`, but I cannot use it in the usernames because the list of usernames is already predefined and I can only use those users. If I could use a scope common to all the workers being created: in this scope I could store a list of credentials, and during user hatching, I can define username that are not duplicated in different workers. – Vitali Aug 28 '20 at 02:44
  • Yea, the problem is that it would require worker-worker communication (which doesnt exist) or at least expanding slave-worker communication. See https://github.com/locustio/locust/issues/1506 for a feature request slightly similar to what you want and a couple of suggestions for workarounds. – Cyberwiz Aug 28 '20 at 06:27
  • I think, that add worker-worker communication is bad idea. But for example, already exists event hook `report_to_master`: "It can be used to attach data to the dicts that are regularly sent to the master. It's fired regularly when a report is to be sent to the master server." Maybe can be added event hook that regulary fired when task at worker being started. – Vitali Aug 31 '20 at 07:49
  • yes, something like that could work. but it does not exist at the moment. – Cyberwiz Aug 31 '20 at 08:33