How do i login concurrently using users passed from json file?

I was performing load testing on an application and i am stuck a point. I believe you will be able to help me here.


• visit a login page
• pass in the username and password
• perform action inside the application
• logout

So far i have been able to complete the flow. I have added the SharedArray for passing in the data through json file. The users from the json file can do the scenario one at a time.

Problem: I want all my users from the json file to log into the system at one time and perform the actions. I haven’t been able to crack this. I will attach my code here. Looking forward to your help.

import { SharedArray } from 'k6/data';
import http from "k6/http";
import { randomIntBetween } from '';
import { sleep } from 'k6';
var todo_id=278;
const url = "url"

let email, password

const json_data = new SharedArray('some data name', function () {
    return JSON.parse(open('./single.json'));

export const options = {
       scenarios: {
      // qa_load_test1: {
      //   executor: 'constant-arrival-rate', 
      //   rate: 1000,
      //   timeUnit: '1m',
      //   duration: '1m',
      //   preAllocatedVUs: 1,
      //   gracefulStop: '5s',
      //   maxVUs: 20
      // },
      qa_load_test2: {
        executor: 'per-vu-iterations', 
        iterations: 1,
        maxDuration: '5m',

//function to call actions

export default function () {
    for (let i of json_data) {
        email =
        password = i.password
        let cookie_1 = get_cookie(email, password);

        get_req_todo_list(url, cookie_1);
        get_req_todo_mytodo(url, todo_id, cookie_1);

I assume the requirement is for uniqueness in these users, that is each virtual user selects one credential set from the shardearry, and no other virtual user can use these credentials?

If so, this post may point you in the right direction.

1 Like

currently, it is picking unique users but one at a time. I want to pick all users from the credentials set and hit the system at one time.

Is it possible?

So each VU gets on set of credentials and then in unison they all try and login?

Loadrunner has a function called rendevous and jmeter has the Synchronizing Timer which would stall the script until all VU’s had caught up to a certain point then do exactly that.

I don’t think it exists in K6 but I could be wrong.

Never been a function I’ve ever had a use case for.

@mnzel, I am not sure I completely understand your use case, but take a look at this answer from the forum thread that @BobRuub linked to: When parameterizing data, how do I not use the same data more than once in a test? - #16 by mark

Does that satisfy your needs? If not, can you explain what the problem is in detail?