How can I convert my array into a list that take one vu for each day in the days array
export default function () {
let days = [];
const first = dayjs();
const last = first.clone().add(3, 'month');
for(let d=first.clone(); d<last; d=d.add(1, 'day') ) {
days.push(d);
}
for(let d of days) {
<run my test scenario>
}
How can I take one line from the days array so I can run it as a vu?
The solution I’m testing is independent on day.
Test is all fine, it is the report that only show one vu.
I have it fixed using a single redis key since ‘INCR’ is atomic,
But the first scenario firstruns twice, even if it is vu:1, iteration:1
and is it possible to just let them run after each other without adding the delayed startTime: '1s'
import dayjs from '../tools/dayjs.min.js';
import utc from '../tools/dayjs-plugin-utc.min.js';
// inject utc plugin to dayjs
dayjs.extend(utc);
import redis from 'k6/x/redis';
const redisClient = new redis.Client(
// URL in the form of redis[s]://[[username][:password]@][host][:port][/db-number
__ENV.REDIS_URL || "redis://127.0.0.1:6379",
);
const redisKey = 'hvdc-k6-date-vu-pos';
let days = [];
const first = dayjs();
const last = first.clone().add(1, 'month');
for(let d=first.clone(); d<last; d=d.add(1, 'day') ) {
days.push(d.format('YYYY-MM-DD'));
}
export const options = {
scenarios: {
first: {
executor: 'shared-iterations',
vus: 1,
iterations: 1,
exec: 'setup',
},
test: {
executor: 'shared-iterations',
vus: 10,
iterations: 30,
exec: 'default',
startTime: '1s'
},
},
};
export async function setup() {
await redisClient.set(redisKey, 0);
console.log(`initialize key '${redisKey}'`);
};
export default async function() {
let myday = undefined;
const exists = await redisClient.exists(redisKey);
if (exists === false) {
throw new Error(`${redisKey} should exist`);
}
let r = parseInt(await redisClient.incr(redisKey));
if(typeof(r)!== 'undefined' && r+1<=days.length) {
myday = days[r-1];
console.log(`doing ${myday}`);
}
};
I found the issue with the first scenario running twice, because it is called setup()
if there is a setup() it is always ran before the scenarios starts. So I just rename it.
So now it is perfect I can set VUS=60 and it will pick unique days. and each only once.