Hi @alex
Can you try with exec.scenario.iterationInTest
as mentioned in Data Parameterization?
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.scenario.iterationInTest;
console.log(
`The index # is ${index}, The VU: ${__VU}, Iteration number: ${__ITER}, name is No. ${index} in ${data.name[index]}`
);
}
Which guarantees it will only be used once:
INFO[0000] The index # is 0, The VU: 1, Iteration number: 0, name is No. 0 in a source=console
INFO[0000] The index # is 1, The VU: 1, Iteration number: 1, name is No. 1 in b source=console
INFO[0000] The index # is 2, The VU: 8, Iteration number: 0, name is No. 2 in c source=console
INFO[0000] The index # is 3, The VU: 8, Iteration number: 1, name is No. 3 in d source=console
INFO[0000] The index # is 5, The VU: 6, Iteration number: 0, name is No. 5 in f source=console
INFO[0000] The index # is 9, The VU: 5, Iteration number: 0, name is No. 9 in j source=console
INFO[0000] The index # is 8, The VU: 6, Iteration number: 1, name is No. 8 in i source=console
INFO[0000] The index # is 4, The VU: 1, Iteration number: 2, name is No. 4 in e source=console
INFO[0000] The index # is 6, The VU: 8, Iteration number: 2, name is No. 6 in g source=console
INFO[0000] The index # is 7, The VU: 9, Iteration number: 0, name is No. 7 in h source=console
If this is not working for your case, let us know.
Cheers!