Hi Team,
I just run loadtest k6 using this script
import http from 'k6/http';
import { check, sleep } from 'k6';
// Accept these status codes as successful
// http.setResponseCallback(
// http.expectedStatuses(200, 201, 202, 204, 302);
// );
// export let options = {
// vus: 5, // Number of virtual users
// duration: '10s', // Test duration
// };
// Load test configuration
export const options = {
stages: [
{ duration: '10s', target: 10 },
{ duration: '10s', target: 20 },
{ duration: '30s', target: 60 },
{ duration: '90s', target: 20 },
{ duration: '10s', target: 10 },
{ duration: '30s', target: 0 },
],
// Explicit failure thresholds (optional)
thresholds: {
http_req_failed: ['rate<0.05'], // Allow <5% failures
http_req_duration: ['p(95)<1500']
}
};
export default function () {
let res = http.get('https://test.k6.io'); // Replace with your API URL
// ✅ Check if response status is 200
check(res, {
'Response status is 200': (r) => r.status === 200,
});
sleep(1); // Simulate real user wait time
}
The result on console like this below
http_req_failed…: 0.00% 0 out of 3732
execution: local
script: ./script-dasar-copy.js
output: -
scenarios: (100.00%) 1 scenario, 60 max VUs, 3m30s max duration (incl. graceful stop):
* default: Up to 60 looping VUs for 3m0s over 6 stages (gracefulRampDown: 30s, gracefulStop: 30s)
█ THRESHOLDS
http_req_duration
✓ 'p(95)<1500' p(95)=1.07s
http_req_failed
✓ 'rate<0.05' rate=0.00%
█ TOTAL RESULTS
checks_total.......................: 3732 20.698302/s
checks_succeeded...................: 100.00% 3732 out of 3732
checks_failed......................: 0.00% 0 out of 3732
✓ Response status is 200
HTTP
http_req_duration.......................................................: avg=409.49ms min=249.09ms med=278.85ms max=4.91s p(90)=713.24ms p(95)=1.07s
{ expected_response:true }............................................: avg=409.49ms min=249.09ms med=278.85ms max=4.91s p(90)=713.24ms p(95)=1.07s
http_req_failed.........................................................: 0.00% 0 out of 3732
http_reqs...............................................................: 3732 20.698302/s
EXECUTION
iteration_duration......................................................: avg=1.44s min=1.24s med=1.28s max=8.5s p(90)=1.8s p(95)=2.21s
iterations..............................................................: 3732 20.698302/s
vus.....................................................................: 1 min=1 max=60
vus_max.................................................................: 60 min=60 max=60
NETWORK
data_received...........................................................: 43 MB 240 kB/s
data_sent...............................................................: 400 kB 2.2 kB/s
But on output.json file we got http_req_failed 3732
"root_group": {
"name": "",
"path": "",
"id": "d41d8cd98f00b204e9800998ecf8427e",
"groups": {},
"checks": {
"Response status is 200": {
"id": "6231ab582661f5cb4ca95f62ebf36012",
"passes": 3732,
"fails": 0,
"name": "Response status is 200",
"path": "::Response status is 200"
}
}
},
"metrics": {
"http_req_failed": {
"passes": 0,
"fails": 3732,
"thresholds": {
"rate<0.05": false
},
"value": 0
},
Can anyone explain why this result ? how to fix it ?
Regards,
Harun