Hi mstoykov,
I try to do load testing with k6, but I meet below issues I want to confirm with you, I am not sure it is whether is bug or design, could you help me to answer it? thanks.
I write two request, one is get request and another one is post request, as below code,
Script output displays “http_req_failed” is 25 % failed rate,
My question1 : I just has one VUS and two api request, and why it is actually has 4 http_reqs, and has 25% failed rate. Note: script run successfully.
question 2: Will the K6 code default to multiple attempts until the request succeeds when the request fails?
question 3: Why is it that there are actually four requests when two requests are written in the code? My virtual user is 1.
import http from "k6/http";
import { check, sleep, fail } from "k6";
import { Rate, Trend, Counter } from "k6/metrics";
let username = "username";
username = encodeURIComponent(username);
let password = "password";
password = encodeURIComponent(password);
const credentials = `${username}:${password}`;
let response;
export default function () {
response = http.get(
`hide here`,
{
auth: "ntlm",
}
);
check(response, {
"0. check the get site api was 200": (res) => res.status == 200,
});
if (response.status != 200) {
console.log("error: message: sites get response not 200" + response.status);
}
response = http.post(
`url-> because of security, so I hide here',
{
headers: {
accept: "application/json, text/plain, */*",
"content-type": "application/json",
"sec-ch-ua":
'" Not A;Brand";v="99", "Chromium";v="102", "Microsoft Edge";v="102"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
auth: "ntlm",
},
}
);
// sleep(2.9);
check(response, {
"1. check the post issues api was 200": (res) => res.status == 200,
});
//console.log(response.body + response.status);
if (response.status != 200) {
console.log("post issues api not 200" + response.status);
}
}
console output:
PS C:\k6-code> k6 run --out influxdb=http://localhost:8086/myk6db "C:\k6-code\k6\dashboard_issues.js"
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: C:\k6-code\k6\dashboard_issues.js
output: InfluxDBv1 (http://localhost:8086)
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
running (00m00.3s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.3s/10m0s 1/1 iters, 1 per VU
**✓ 0. check the get site api was 200**
** ✓ 1. check the post issues api was 200**
checks.........................: 100.00% ✓ 2 ✗ 0
data_received..................: 6.6 kB 23 kB/s
data_sent......................: 2.0 kB 6.9 kB/s
http_req_blocked...............: avg=24.62ms min=0s med=0s max=98.51ms p(90)=68.96ms p(95)=83.73ms
http_req_connecting............: avg=249.67µs min=0s med=0s max=998.7µs p(90)=699.09µs p(95)=848.89µs
http_req_duration..............: avg=46.76ms min=999.9µs med=20.5ms max=145.03ms p(90)=113.52ms p(95)=129.28ms
{ expected_response:true }...: avg=62.01ms min=1ms med=40ms max=145.03ms p(90)=124.03ms p(95)=134.53ms
http_req_failed................: 25.00% ✓ 1 ✗ 3
http_req_receiving.............: avg=250.12µs min=0s med=0s max=1ms p(90)=700.35µs p(95)=850.42µs
http_req_sending...............: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_tls_handshaking.......: avg=23.87ms min=0s med=0s max=95.51ms p(90)=66.86ms p(95)=81.18ms
http_req_waiting...............: avg=46.51ms min=999.9µs med=20ms max=145.03ms p(90)=113.22ms p(95)=129.13ms
http_reqs......................: 4 13.958965/s
iteration_duration.............: avg=285.55ms min=285.55ms med=285.55ms max=285.55ms p(90)=285.55ms p(95)=285.55ms
iterations.....................: 1 3.489741/s
Regards
Lambda