User Unique Data from CSV and Repeat again if the file reach to end

I need to use the csv as unique and once the reading end of the file again start reading from starting of the file.

like i have 25 data set in csv, I run 10 users with 10 iterations, so the data users first 10 unique and then next 10 users users and then last 5 and pick next 5 from again top.

how to implement this logic with k6 either use the scenario option or pure JAVAScript.

Thanks in advanced!


If I understand you correctly you want, that every iteration would get the next line from the csv, and if there is an end of file, then it would start over from the beginning of the file.

I would use someting like this:



import papaparse from '';
import exec from 'k6/execution';
import { SharedArray } from "k6/data";

const users = new SharedArray("users", function () {
  return papaparse.parse(open('./data.csv'), { header: true }).data;

export default function () {
  let user = users[exec.scenario.iterationInTest % users.length];
  console.log('user:', user.username, ', pass:', user.password);

I hope this helps.

Hi @bandorko Thanks… I sm using this same code… but I missed this part “% users.length”

Thanks for your prompt reply

1 Like