Files
petclinic/k6/load-test.js
demo-bot ff5dc8b590
Some checks failed
CI Pipeline / Build and Test (push) Has been cancelled
Build and Publish TechDocs / build-and-publish (push) Failing after 2s
feat(k6): add bespoke load test script
2026-03-24 18:21:52 +00:00

140 lines
4.2 KiB
JavaScript

import http from 'k6/http';
import { check, sleep, group } from 'k6';
const vus = parseInt(__ENV.TEST_VUS || '10');
const duration = __ENV.TEST_DURATION || '30s';
const targetUrl = __ENV.TARGET_URL || 'http://petclinic.demo-apps.svc.cluster.local:80';
export const options = {
scenarios: {
load_test: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: ''10s'', target: vus },
{ duration: duration, target: vus },
{ duration: '5s', target: 0 },
],
},
},
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
group('System API', () => {
let res = http.get(`${targetUrl}/`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/oups`);
check(res, {
'status is 500': (r) => r.status === 500,
'response time < 500ms': (r) => r.timings.duration < 500,
});
});
sleep(0.5);
group('Owner API', () => {
let res = http.get(`${targetUrl}/owners/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/new`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890');
check(res, {
'status is 302': (r) => r.status === 302,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/find`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/edit`, 'firstName=John&lastName=Doe&address=123+Main+St&city=Springfield&telephone=1234567890');
check(res, {
'status is 302': (r) => r.status === 302,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/pets/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/new`, 'name=Buddy&birthDate=2023-01-01&type=Dog');
check(res, {
'status is 302': (r) => r.status === 302,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/pets/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/1/edit`, 'name=Buddy&birthDate=2023-01-01&type=Dog');
check(res, {
'status is 302': (r) => r.status === 302,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/owners/1/pets/1/visits/new`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.post(`${targetUrl}/owners/1/pets/1/visits/new`, 'description=Annual+checkup');
check(res, {
'status is 302': (r) => r.status === 302,
'response time < 500ms': (r) => r.timings.duration < 500,
});
});
sleep(0.5);
group('Vet API', () => {
let res = http.get(`${targetUrl}/vets.html`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${targetUrl}/vets`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
});
sleep(0.5);
}