I'm looking for a solution but I've gone through various configurations but haven't been able to get a satisfactory result.
What do I need to do? The queue takes 4 IDs and passes them on for execution one by one, wait until the task on the queue ends or the time for executing the task exceeds, then it takes the next one.
So, I need to take a list of 4 ids, which are executed in the queue. First, one ID adds the request url and needs to wait until the execution finishes and returns a response. If the execution time exceeds 7 min. this should return me http code 400. Initially, I would like the entire test to last a maximum of 30 minutes.
This is what my code looks like:
import http from 'k6/http';
import { expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';
import { check, sleep } from 'k6';
let idsParam = `
1
2
3
4
5
6
`;
let params = {
timeout: '780s',
};
export const optons = {
vus: 1,
timeout: '480s',
duration: '10m',
};
let data = idsParam.trim().split('\n').slice(1).map(row => row.trim());
export default async function () {
for (let id of data) {
let url = `https://pagequeue.com/task/{id}`;
console.info(`Request for ID ${id} `);
let res = await http.asyncRequest('GET', url, null, params);
// Wait until the request is processed
if (res.status != 200) {
console.warn(`Request for ID ${id} is still processing with status ${res.status}...`);
console.warn(res);
sleep(60);
}
// Check if the response status is 200 or 400, mark as failure otherwise
check(res, {
'Status is 200': (r) => r.status === 200,
});
// Check if the response status is 200 or 400, mark as failure otherwise
check(res, {
'Status is 400': (r) => r.status === 400,
});
expect(res.status).to.equal(200);
}
}
For tasks that are on the queue up to 1 min. it works great, but for requests that take longer 3 minutes, not wait but take another request with id. Despite increasing the timeout waiting for asynchronous responses from the http request, it doesn't work for me, only the test ends, also despite setting the time to 20 minutes. it ends after 10m 30sec. On the queue side, the service is prepared to return http code responses. I checked this on jmeter and it works beautifully there. Currently I need to use my k6 to write a test. Can anyone suggest what it should look like?
I found solution for my case. Maybe it will be useful to someone. What i wrote:
On the top i added
params
where put timeout, how long we wait for finish request. Default value for timeout is 60 seconds.