56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import http from 'k6/http';
|
|
import { check, sleep } from 'k6';
|
|
import { Rate, Trend } from 'k6/metrics';
|
|
|
|
const errorRate = new Rate('errors');
|
|
const responseTime = new Trend('response_time');
|
|
|
|
export const options = {
|
|
stages: [
|
|
{ duration: '30s', target: 10 },
|
|
{ duration: '1m', target: 50 },
|
|
{ duration: '30s', target: 100 },
|
|
{ duration: '30s', target: 0 },
|
|
],
|
|
thresholds: {
|
|
errors: ['rate<0.1'],
|
|
http_req_duration: ['p(95)<500', 'p(99)<1000'],
|
|
response_time: ['p(95)<500'],
|
|
},
|
|
};
|
|
|
|
const BASE_URL = __ENV.BASE_URL || 'http://localhost:3001';
|
|
|
|
export default function () {
|
|
const response = http.get(`${BASE_URL}/api/cv`);
|
|
|
|
check(response, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'has personal data': (r) => {
|
|
const body = r.json();
|
|
return body.personal && body.personal.name;
|
|
},
|
|
'has experience array': (r) => {
|
|
const body = r.json();
|
|
return Array.isArray(body.experience);
|
|
},
|
|
'has skills object': (r) => {
|
|
const body = r.json();
|
|
return body.skills && typeof body.skills === 'object';
|
|
},
|
|
'response time < 200ms': (r) => r.timings.duration < 200,
|
|
});
|
|
|
|
errorRate.add(response.status !== 200);
|
|
responseTime.add(response.timings.duration);
|
|
|
|
sleep(1);
|
|
}
|
|
|
|
export function handleSummary(data) {
|
|
return {
|
|
'stdout': JSON.stringify(data, null, 2),
|
|
'tests/performance/results.json': JSON.stringify(data, null, 2),
|
|
};
|
|
}
|