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
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.
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.