Hi,
Is there a way to read data in a CSV file 1 row at a time? I tested it with exec.vu.idInTest
, however it cannot guarantee the order. Below is a simple script how did I test it. Assume the list is the csv file, it cannot guarantee to read one element per execution when multiple users running concurrently.
import http from "k6/http";
import exec from "k6/execution";
export const options = {
scenarios: {
PerVU: {
executor: "shared-iterations",
iterations: 10,
vus: 10,
},
},
};
export function setup() {
const name = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
];
console.log("setup() function is executed!");
return { name };
}
export default function (data) {
let index = exec.vu.idInTest - 1;
console.log(
`The index # is ${index}, The VU: ${__VU}, Iteration number: ${__ITER}, name is No. ${index} in ${data.name[index]}`
);
}
Below is the example, as you can see, exec.vu.idInTest couldn’t guarantee the uniqueness at each execution.
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 8, The VU: 9, Iteration number: 0, name is No. 8 in i" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 4, The VU: 5, Iteration number: 0, name is No. 4 in e" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 7, The VU: 8, Iteration number: 0, name is No. 7 in h" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 5, The VU: 6, Iteration number: 0, name is No. 5 in f" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 1, The VU: 2, Iteration number: 0, name is No. 1 in b" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 0, The VU: 1, Iteration number: 0, name is No. 0 in a" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 6, The VU: 7, Iteration number: 0, name is No. 6 in g" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 8, The VU: 9, Iteration number: 1, name is No. 8 in i" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 3, The VU: 4, Iteration number: 0, name is No. 3 in d" source=console
time="2023-03-10T00:56:13-08:00" level=info msg="The index # is 9, The VU: 10, Iteration number: 0, name is No. 9 in j" source=console