Reputation: 1043
I have written a simple K6 Load testing script that performs a successful login. I have written a separate K6 Load testing script that performs an unsuccessful login attempt
They are currently separate scripts that you have to run on their own.
What I want to know is how do you simulate users performing different scenarios in one load test? e.g. valid login, invalid login, logout, any other actions.
Do you put the different scenarios all in one script?
Upvotes: 0
Views: 5621
Reputation: 1219
There are two approaches the "old" and the "new" (from v0.27.0) onward. The old approach is to have a default function that chooses to do one or the other on some condition, for example, each third VU iteration is unsuccessful, the others are successfule ones:
export default function() {
if (__ITER % 3 == 2) {
call_to_unsuccessful_login();
} else {
call_to_successful_login();
}
}
In the above example, you obviously need to define the two functions either in the same script or import them from another
After v0.27.0 and the new execution model, you have multiple scenarios using different executors each execution a different "default" function. So in this case instead of having one default function which chooses, we can configure different execution plans for the successful and unsuccessful logins and directly call the functions that do them.
export let options = {
"scenarios": {
"successful": {
"executor": "constant-vus".
"vus": 2,
"duration": 1m,
"exec": "call_to_successful_login"
},
"unsuccessful": {
"executor": "constant-vus".
"vus": 1,
"duration": 1m,
"exec": "call_to_unsuccessful_login"
}
}
}
In this case both call... functions need to also be exported in the main script.
You can read more on how to configure scenarios and their different options in the documentation.
Upvotes: 3