Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
K6 unique data per scenario

I am creating a test with two scenarios with different amount of users and ramp-up time. The idea is that each user shall login once to retrieve a SSO-cookie, that shall be used in subsequent requests. The user data is stored in one json-file and each group of users are parsed to two shared arrays, one for each scenario. The users are grouped in the JSON with different roles and accesses rights so they can't be mixed.

The below code works pretty well if you don't have that many users and "correct" sleep in business logic part, else it will get out sync in regards of exec.scenario.iterationInTest. I am not able to use VU id either since VU id is per test and not per scenario.

Anyone who has any workaround for this?

At the moment I am calling a third party API-counter to get numbers in order to get unique users for each scenario but I don't like that solution. It would be great to have a unique VuserID per scenario starting from 1.

import { SharedArray } from "k6/data";
import jsonpath from "https://jslib.k6.io/jsonpath/1.0.2/index.js"

import { login } from '../requests/login.js';

const testdata = JSON.parse(open('../data/testdata.json'));
const usersA = new SharedArray("usersA", function () { return jsonpath.value(testdata, '$.usersA') });
const usersB = new SharedArray("usersB", function () { return jsonpath.value(testdata, '$.usersB') });

let user;
const usersARampUp = usersA.length * 2;
const usersBRampUp = usersB.length * 9;


export const options = {
    scenarios: {
        loginUserA: {
            executor: 'ramping-vus',
            exec: 'userA',
            startVUs: 0,
            stages: [
                { duration: usersARampUp + 's', target: usersA.length },
                { duration: '10m', target: usersA.length }
            ]
        },
        loginUserB: {
            executor: 'ramping-vus',
            exec: 'userB',
            startVUs: 0,
            stages: [
                { duration: usersBRampUp + 's', target: usersB.length },
                { duration: '10m', target: usersB.length }
            ]
        }
    }
};

export function userA() {
    let dataCounter = exec.scenario.iterationInTest;

    if (__ITER == 0) { //Only login once per test to retrieve SSO cookie
        user = usersA[dataCounter];
        login(user.userName, user.password); //SSO-cookie is set in cookieJar
    }
  //Business logic after login and SSO cookie is retrieved
}

export function userB() { 
    let dataCounter = exec.scenario.iterationInTest;

    if (__ITER == 0) { //Only login once per test to retrieve SSO cookie
        user = usersB[dataCounter];
        login(user.userName, user.password); //SSO-cookie is set in a cookieJar
    }
  //Business logic after login and SSO cookie is retrieved
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda