Setup function duration


Hello everyone!

I need to make performance test with e.g. 100 users, adding according to stages.
All these users must authenticate first.
I’ve moved authentication of users into setup() function in purpose to not impact on test execution.
But now it takes at about 60sec to login all users before test starts. And what if I want to simulate 1000 users? Several minutes of waiting?

Is it possible to somehow solve this issue and make it faster?
Maybe there is an ability to create some function, that will be run before each user adding to simulation?

Thx :slight_smile:

ADFS SSO Authentication


There are … a couple of possible solutions which depend on how your script is working. I am going to list them in the order I think is best but it depends on your needs :slight_smile:

  1. If each VU is essentially one user or you can map n user to a specific VU you can just authenticate them in the first iteration of the VU(or the first iteration you use the given user). VUs keep their global variables between iterations so you can just:
let authToken = ""
export default function() {
    if __ITER == 0 || authToken =="" { // which ever is easier
        authToken = ... // however you get your token
    // use the token 

This obviously will add some time to the execution of that iteration but it will be spread between the VUs and if you make a lot of iterations (which you probably do) I would guess it won’t be that big of a difference that it will skew your end results.

This will have a better/nicer way of doing it with the introduction of InitVU but this is currently not supported, but you can watch if for change

  1. Make all the authentications in a http.Batch request in setup() … this should speed up the process somewhat
  2. You can raise the setupTimeout so at least it finishes if that is your current problem or none of the other help
  3. You can authenticate outside of k6, write the tokens to a json file and (re)use it in the script with open one of the examples is somewhat what you want.

If you have any suggestion on how we can provide a better functionality for your use case maybe write us an issue :wink:

1 Like
How to execute task only once


Thank you for so fast response. Yeah, we thought about these ways. The first way is closest to one we are looking for.
However, it makes tests are not so clean as we are doing setup actions in the main body itself. Usually, in test frameworks there are “SuiteSetup” and “TestSetup” which in case of data driven tests (the same as having tests under many users) are run before test and before each case specifically.

I think the first option will work for us but initial concern is still relevant I guess and t might be just a small feature request across community (just to make tests clean).