Spawn (extra) users inside a running Task(Set)? #3334
-
|
Hello, I have a bit of an odd request: is it possible to spawn extra users from within a running user's task? The question behind the question is that I'm testing a fraud detection system. I was thinking about having 'regular' traffic, however, with a certain (low) chance I would like a secondary 'fraud user' to arrive on the scene. At that moment I need data from one of the sessions that a regular user is currently having (roughly cookies). I was thinking if it was possible to spawn a 'fraudster' from a 'regular user' because at that moment I have easy access to that data. Does that make sense? Does anybody have other options? I think sharing data between different users is difficult? It'll probably be difficult to not slow down 'threads' (I don't think they're real threads) with locking etc. Once again: I'm not a Python/Locust expert by any means. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hmm... Is the "fraud user" just a new TCP/HTTP connection with stolen cookies? If so, it's entirely possible to do, but not exactly trivial. You can access the individual cookies and add them to a second, newly connected Session object. If the fraud user is always tied to a single "real" user, I wouldnt bother creating an extra user/greenlet. If you're using FastHttpUser you can access individual cookies you can access them like this (HttpUser is probably only slightly different, but I dont have an example at hand): |
Beta Was this translation helpful? Give feedback.
Here's an example of how to maintain a second client in the same User instance: https://github.com/locustio/locust/blob/f3f2985f4b8783448eba3e8e85078b873aab30ea/examples/multiple_hosts.py
Probably you wouldnt need it, but if you must have actual concurrency within the same User, here's an example: https://docs.locust.io/en/latest/increase-performance.html#concurrency (these are using the same session, but you might be able to combine the two approaches)
I think actually creating a full User inside another one is not a good idea :)