Parallel/async code in setup() or scenarios chains

Hi!

I’ve got big CSV with a lot of users credentials and scenario with multiple subscenarios for different endpoints with various RPS. Before executing these subscenarios I need to get login tokens for users credentials that I have and I use setup() function for this. But sync logins for such amount of users are very slow and nonoptimal. Is there a way to solve it? I’ve seen “Test suites / execute multiple scripts with k6” Test suites / execute multiple scripts with k6 · Issue #1342 · grafana/k6 · GitHub, which is still in progress, but maybe there is some other way which I could not found?

HI @Gim6626 , welcome to the community forum, and sorry for the late reply.

I will probably need more info in order to give you a better answer but let me point out some things:

  1. Use SharedArray for the credentials
  2. as setup will need to return the tokens (or w/e you will be using to point out that a user is logged in) and that this data will at least at the moment be copied per vu I would recommend not doing that.
  3. My general recommendation will be to just login users as needed when you need them to and cache the token, this will likely mean that you will need to map users to VUs so that 1 VU is logging as 1+ users, but multiple VUs aren’t logging with the same user.
  4. You can try to have a per VU setup to do all that as shown in Setup and Teardown running by Virtual User? - #3 by nedyalko but I would expect this will be quite finicky for complex cases.

Hope this helps you and if you have any more questions, ask away :slight_smile: