VU UID increment within a specific numerical range

Hello,

Within k6, I was using the counter to increment the user ids for the session. By default, it would begin with zero and increment to whichever VU count it reached.

Now, I need to implement a concurrent scenarios with simultaneous tests running within different ranges of ids. For instance, test1 has to increment from userid “1” to userid “30”. The second, concurrent test is to increment from userid “31” to userid “60” and so on.

How can I configure the Counter function (or any other function) to operate within a fixed ranges of numbers per test?

Cheers,
Gavin

Hi @gavindelatour

You can use randonIntBetween, this functions is randomic into a number (min, max)

Another way is create a function using the VU UID, for this you use iterationInScenario, this variable have the identifier of the iteration in the current scenario for this VU. This is only unique for current VU and scenario it is currently executing. In the documentation you have more information

For example in my job I created a function wich use the sequency item of VUs to get the value in .csv data

import { exec, scenario } from "k6/execution";
function sequencyItem(arrayOfItems) {
	return arrayOfItems[scenario.iterationInTest];
}