I am running a K6 tests with request.batch where number of requests can change for each test.
req = [req0, req1, req2, ...];
let res = http.batch(req);
then, I am trying to run a "check" for each request, and I use a while loop to do so.
while (i < req.length) {
check(
res[i],
{" ${i} - status 200": (r) => r.status === 200 }
);
i++;
}
however K6 accumulate all "check" tests results in a single test, as test message doesn't parse the variable I pass. the output prints this message at the end of the test:
done [===============] 10s / 10s
✓ ${i} - status 200
I have tried to use different ways add the parameters, but no use:
{ i + " - status 200": (r) => r.status === 200 }
{' ${i} - status 200': (r) => r.status === 200 }
{` ${i} - status 200`: (r) => r.status === 200 }
{" %d - status 200", i : (r) => r.status === 200 }
I would like to know if there is any why to pass a customized message here.
You can use the bracket notation for assigning the property name.
See the example below and the following link: How to create an object property from a variable value in JavaScript?
import http from "k6/http";
import { check } from "k6";
export default function() {
let response = http.get("https://test.loadimpact.com");
let test = "x";
check(response, {
[test + " - status 200"]: (r) => r.status === 200
});
};
This results in the following output:
done [==========================================================] 1 / 1i
✓ x - status 200
checks.....................: 100.00% ✓ 1 ✗ 0
data_received..............: 6.8 kB 15 kB/s
data_sent..................: 527 B 1.2 kB/s
http_req_blocked...........: avg=362.37ms min=362.37ms med=362.37ms max=362.37ms p(90)=362.37ms p(95)=362.37ms
http_req_connecting........: avg=138.16ms min=138.16ms med=138.16ms max=138.16ms p(90)=138.16ms p(95)=138.16ms
http_req_duration..........: avg=91.62ms min=91.62ms med=91.62ms max=91.62ms p(90)=91.62ms p(95)=91.62ms
http_req_receiving.........: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_sending...........: avg=992.2µs min=992.2µs med=992.2µs max=992.2µs p(90)=992.2µs p(95)=992.2µs
http_req_tls_handshaking...: avg=214.19ms min=214.19ms med=214.19ms max=214.19ms p(90)=214.19ms p(95)=214.19ms
http_req_waiting...........: avg=90.63ms min=90.63ms med=90.63ms max=90.63ms p(90)=90.63ms p(95)=90.63ms
http_reqs..................: 1 2.207509/s
iteration_duration.........: avg=453.99ms min=453.99ms med=453.99ms max=453.99ms p(90)=453.99ms p(95)=453.99ms
iterations.................: 1 2.207509/s
vus........................: 1 min=1 max=1
vus_max....................: 1 min=1 max=1