I tried to follow the same, but somehow, it doesnt work.
import { sleep } from āk6ā;
const VUs = 800; // adjust this if you want more or less concurrency
var functionalTests = [
require(ā./LocationItemServices-clubItem-loadTest.jsā).default,
require(ā./locationItemServices-dcItem-loadTest.jsā).default];
function getTest(i) {
return function () {
return āTest #ā + i;
}
}
for (var i = 0; i < 2; i++) {
functionalTests.push(getTest(i));
}
const testsPerVU = Math.ceil(functionalTests.length / VUs);
export let options = {
scenarios: {
contacts: {
executor: āper-vu-iterationsā,
vus: VUs,
iterations: testsPerVU,
maxDuration: ā30sā,
},
},
};
export default function () {
var myTestNumber = (__VU - 1) * testsPerVU + __ITER
if (myTestNumber >= functionalTests.length) {
return; // last VU might have more iterations than needed
}
console.log(`VU ${__VU}, iter ${__ITER}, executed ${functionalTests[myTestNumber]()}`);
sleep(1);
}
LocationItemServices-clubItem-loadTest file:
import grpc from āk6/net/grpcā;
import { sleep } from āk6ā;
import { check } from āk6ā;
const client = new grpc.Client();
client.load([ādefinitionsā], āitem_apis.protoā);
let data = open(ā./clubItemIds.csvā);
data = data.split(ā\nā);
export let options = {
stages: [
{ duration: ā2mā, target: 30 }, // simulate ramp-up of traffic from 1 to 30 users over 5 minutes.
{ duration: ā5mā, target: 30 }, // stay at 30 users for 30 minutes
{ duration: ā2mā, target: 0 }, // ramp-down to 0 users
],
};
export default () => {
if (__ITER == 0) {
client.connect(āstg-score-item-services.walmart.com:80ā, {
plaintext: true,
timeout:ā2sā
});
}
let ids = [];
let set = new Set();
for(let i = 0; i < 10; i++) {
let id = getRandomId();
while(set.has(id)) {
id = getRandomId();
}
set.add(id);
ids.push(`"${id}"`);
}
let queryMulti = `{
āitemIdsā: [${ids}],
ālocationIdā:6612
}`;
const requestPayload = JSON.parse(queryMulti);
const response = client.invoke(ācom.sams.catalog.item.services.LocationItemService/GetLocationItemsā, requestPayload);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
if(response.status != grpc.StatusOK){
console.log(JSON.stringify(response.body));
}
sleep(0.02);
};
function getRandomId() {
let randomNumber = Math.floor(Math.random() * 20);
return ${data[randomNumber]}
;
}