Multiple scenarios with multiple data files

Hi Support

I have a script below, the current __VU approach is good for a single csv data file.
How do I assign each vu has a unique login id with multiple scenarios?

dataLoginBP01.csv
1
2
3

dataLoginBP02.csv
11
12
13

const csvData_bp01 = new SharedArray("bp01", function () {
    return papaparse.parse(open('./dataLoginBP01.csv'), { header: false }).data;
});
const csvData_bp02 = new SharedArray("bp02", function() {
    return papaparse.parse(open('./dataLoginBP02.csv'), { header: false }).data;
});

export const options = {
    scenarios: {
        contributeTranslateTask: {
            executor: 'per-vu-iterations',
            exec: 'contributeTranslateTask',
            vus: 1,
            iterations: 3,
            maxDuration: '1m',
        },
        contributeProofreadingTask: {
            executor: 'per-vu-iterations',
            exec: 'contributeProofreadingTask',
            vus: 1,
            iterations: 3,
            maxDuration: '1m',
        },
    },
};

export function contributeTranslateTask() {
    // STUB: Code inside default is called "VU code", and is run over and over for as long as the test is running
    console.log("bp01Id=" + csvData_bp01[(__VU -1) % csvData_bp01.length].id + " |VU=" + __VU + " |ITER=" + __ITER )

}

export function contributeProofreadingTask() {
    console.log("bp02Id=" + csvData_bp02[(__VU -1) % csvData_bp02.length].id + " |VU=" + __VU + " |ITER=" + __ITER)
}

Current behaviour
VU1 == loginId 1
VU2 == loginId 12

Expected behaviour
VU1 == loginId 1
VU2 == loginId 11

This is something that will hopefully be fixed in k6 v0.33.0 with https://github.com/k6io/k6/pull/1863

In the meantime you can use Extensions like xk6-counter (assuming you are running just a single instance of k6, otherwise you may need to use xk6-segment).

really appreciate your reply. Unfortunate, due to timeline constraint, I need to use a cheat method to overcome this issue. I will follow up again when v0.33.0 release ready to use.

I also search for forum, do you have any github sample code how can i integrate any k6 extension?

If you are looking for a unique ID per VU and per scenario that starts at 1, then I would suggest installing xk6, building a k6 executable with xk6-segment, and using code like this:

import { SharedSegmentedIndex } from "k6/x/segment";

const csvData_bp01 = new SharedArray("bp01", function () {
    return papaparse.parse(open('./dataLoginBP01.csv'), { header: false }).data;
});
const csvData_bp02 = new SharedArray("bp02", function() {
    return papaparse.parse(open('./dataLoginBP02.csv'), { header: false }).data;
});

let vuIdx;

export const options = {
    scenarios: {
        contributeTranslateTask: {
            executor: 'per-vu-iterations',
            exec: 'contributeTranslateTask',
            vus: 1,
            iterations: 3,
            maxDuration: '1m',
        },
        contributeProofreadingTask: {
            executor: 'per-vu-iterations',
            exec: 'contributeProofreadingTask',
            vus: 1,
            iterations: 3,
            maxDuration: '1m',
        },
    },
};

export function contributeTranslateTask() {
    // STUB: Code inside default is called "VU code", and is run over and over for as long as the test is running

  // set the VU index only on the first iteration
  if (__ITER === 0) {
    const index = new SharedSegmentedIndex("script1");
    vuIdx = index.next();
  }

  console.log("bp01Id=" + csvData_bp01[vuIdx].id + " |VU=" + __VU + " |ITER=" + __ITER )
}

export function contributeProofreadingTask() {
  if (__ITER === 0) {
    const index = new SharedSegmentedIndex("script2");
    vuIdx = index.next();
  }
  
  console.log("bp02Id=" + csvData_bp02[vuIdx].id + " |VU=" + __VU + " |ITER=" + __ITER)
}

If you need the VU index to increment with each iteration, you’ll need to change up the code a bit.

great to see the sample code for me to try. Do you have any idea why it will throw this error?
ERRO[0001] GoError: unknown module: k6/x/segment

I need to go through this guide to make my ubuntu machine has the xk6? no possible through here with extension right?

Yes: xk6 requires that you build a custom k6 binary that includes the extension you are wanting to use.