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!

@venkatareddy

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:
data.csv:

username,password
user1,pass1
user2,pass2
user3,pass3
user4,pass4

script.js:

import papaparse from 'https://jslib.k6.io/papaparse/5.1.1/index.js';
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