How to generate unique date per vus in loop?

Hello!

I want to generate the date parameter for each vus in loop in unique way by adding one hour.

I have json file with test data and the following logic to init dates. This scenario works fine only when I use 1 iteration in loop. But if there are more iterations then one, dates duplicate. How to fix the problem with dates duplicate ? Implementation in the attachment.

{
  "offset1": 0,
  "offset2": 1,
  "offset3": 2,
  "offset4": 3,
  "offset5": 4,
  "offset6": 5,
  "offset7": 6,
  "offset8": 7,
  "offset9": 8,
  "offset10": 9,
  "offset11": 10,
  "offset12": 11,
  "offset13": 12,
  "offset14": 13,
  "offset15": 14
}
export function betList() {

    group("BetList", function () {
        let offset;
        for (let counter = 0; counter < 5; counter++) {
            offset = dateParams['offset' + __VU];
            let dates = initFilterDates(true, false, offset);
            let result = GetBetList(dates, true, false);
            check(result, {
                'has status 200': (result) => result.status === 200,
            });
        }
    });
}

dates offset implementation

export function initFilterDates(useCreatedFilter, useSettledFilter, startHoursOffset) {
    let currDate = new Date();
    let startDate;
    let startTime;
    startDate = currDate;
    if (useCreatedFilter === true && useSettledFilter === false) {
        // start date offset for requests
        startTime = new Date(startDate.setHours(startDate.getHours() + startHoursOffset));
    } else if (useSettledFilter === true && useCreatedFilter === false) {
        // start date offset for requests
        startTime = new Date(startDate.setHours(startDate.getHours() + startHoursOffset));
    }
    let dateObj = {
        startTime: startTime.toLocaleString(),
    };
    return dateObj;
}

CreatedDate parameter in log files:


Hi @Daniil,

From what I gather you want the for each iteration of each VU for you to get a different time. But you only base the calculation on the __VU, but not the __ITER variable.

So as far as I can see you should just use __ITER in the initFilterDates calculation ā€¦ somehow - that is up to you whether you will just add __ITER to the end result and say that for each iteration the startTime is a second later or you will do something more complicated.

Hope this helps

1 Like

@mstoykov , thank you for the help!
Iā€™'ll try to use __ITER parameter in dates calculating.