Multiple scenarios

I have two scenarios which I need to run in Parallel, each csv data file has 22 rows,

export const users = new SharedArray('another data name', function () {
  // Load CSV file and parse it using Papa Parse
  return papaparse.parse(open('file1.csv'), { header: true }).data;
})
export const users1 = new SharedArray('another data name', function () {
  // Load CSV file and parse it using Papa Parse
  return papaparse.parse(open('file2.csv'), { header: true }).data;
})

 executor: 'ramping-vus',
    startVUs: 0,
    stages: [
      { target: 20, duration: '100s' },
      { target: 20, duration: '10m' },
export  function testCase10_ProjectCrud() {
   globalThis.chosenUser = users[vu.idInTest - 1];
console.log(`[VU: ${exec.vu.idInTest - 1}, iteration: ${exec.scenario.iterationInTest}] Starting iteration...ProjectCrud_EAV`);
  loginHelper();
}

export  function testCase11_ProjectCrud() {
   globalThis.chosenUser = users1[vu.idInTest - 1];
console.log(`[VU: ${exec.vu.idInTest - 1}, iteration: ${exec.scenario.iterationInTest}] Starting iteration...ProjectCrud_EAV`);
  loginHelper(); 
}

The problem is it run ok for 22 users, but starts looking for 23 and it fails…since there are 22 rows, but it should pick 20usersfrom first file and 20 from second file…

What is that i am doing wrong?

Hi @jrevalle

Based on the example for a ramping vus executor, I would say the behavior is caused by choosing the CSV record based on vu.idInTest. You do have a target of 20 VUs.

However, if you run multiple executors simultaneously, the total VUs running in parallel is 40, and the ids range from 1 to 40, not 1 to 20 (or 22 that you have). And then you would see the error, you are going out of bounds with almost half of the virtual users, from id 23 to 40.

I’ll share an example that might help, based on the information you can find in:

I create a couple of local files, file1.csv and file2.csv with 5 entries:

username
file1-01
file1-02
file1-03
file1-04
file1-05
username
file2-01
file2-02
file2-03
file2-04
file2-05

And the script:

import { SharedArray } from "k6/data";
import { scenario, vu } from 'k6/execution';
import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';

const sharedData1 = new SharedArray("Shared Usernames 1", function () {
    let data = papaparse.parse(open('file1.csv'), { header: true }).data;
    return data;
});

const sharedData2 = new SharedArray("Shared Usernames 2", function () {
    let data = papaparse.parse(open('file2.csv'), { header: true }).data;
    return data;
});

export const options = {
    scenarios: {
        'use-all-the-data-file1': {
            executor: 'ramping-vus',
            startVUs: 0,
            stages: [
                { target: 5, duration: '5s' },
                { target: 5, duration: '10s' },
            ],
            exec: "test1",
        },
        'use-all-the-data-file2': {
            executor: 'ramping-vus',
            startVUs: 0,
            stages: [
                { target: 5, duration: '5s' },
                { target: 5, duration: '10s' },
            ],
            exec: "test2",
        },
    },
};

export function test1() {
    console.log('test1 // ', 'vu', vu.idInTest, 'iteration', scenario.iterationInTest, 'username: ', sharedData1[(vu.idInTest - 1) % sharedData1.length].username);
}

export function test2() {
    console.log('test1 // ', 'vu', vu.idInTest, 'iteration', scenario.iterationInTest, 'username: ', sharedData2[(vu.idInTest - 1) % sharedData2.length].username);
}

Running the script:

The VU id is between 1 and 10, as I have 2 scenarios, each with a target of 5. The same length of the files in my case, 5. The trick here lies in sharedData1[(vu.idInTest - 1) % sharedData1.length].

There are several alternatives to fix the behavior, depending on your case. I went with this example since you did not share the complete script and what you wanted to achieve was unclear.

I’d suggest you experiment using console.log() as I did. Initially print the array positions you read, not the values in the array, so you can figure out if you would be going out of bounds and why.

I hope this helps.

Cheers!

Thank you eyeveebe…That worked perfectly…

1 Like