feat(k6): add bespoke load test script
Some checks failed
Build and Publish TechDocs / build-and-publish (push) Has been cancelled
CI Pipeline / Build and Test (push) Has been cancelled

This commit is contained in:
2026-03-24 14:05:31 +00:00
parent 4e35b5fb01
commit 1c42bc739c

154
k6/load-test.js Normal file
View File

@@ -0,0 +1,154 @@
import http from 'k6/http';
import { check, sleep, group } from 'k6';
export const options = {
scenarios: {
load_test: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: ''10s'', target: 10 },
{ duration: ''30s'', target: 10 },
{ duration: '5s', target: 0 },
],
},
},
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
const BASE_URL = 'http://petclinic.demo-apps.svc.cluster.local:80';
export default function () {
group('System API', () => {
let res = http.get(`${BASE_URL}/`);
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
res = http.get(`${BASE_URL}/oups`);
check(res, {
'status is 500': (r) => r.status === 500,
});
});
sleep(0.5);
group('Owner API', () => {
let res = http.get(`${BASE_URL}/owners/new`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.post(`${BASE_URL}/owners/new`, JSON.stringify({
firstName: 'John',
lastName: 'Doe',
address: '123 Main St',
city: 'Springfield',
telephone: '1234567890',
}), {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${BASE_URL}/owners/find`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.get(`${BASE_URL}/owners`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.get(`${BASE_URL}/owners/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.post(`${BASE_URL}/owners/1/edit`, JSON.stringify({
firstName: 'Jane',
lastName: 'Doe',
address: '456 Elm St',
city: 'Springfield',
telephone: '9876543210',
}), {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${BASE_URL}/owners/1`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.get(`${BASE_URL}/owners/1/pets/new`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.post(`${BASE_URL}/owners/1/pets/new`, JSON.stringify({
name: 'Buddy',
birthDate: '2020-01-01',
type: { id: 1, name: 'Dog' },
}), {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${BASE_URL}/owners/1/pets/1/edit`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.post(`${BASE_URL}/owners/1/pets/1/edit`, JSON.stringify({
name: 'Buddy',
birthDate: '2020-01-01',
type: { id: 1, name: 'Dog' },
}), {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'status is 302': (r) => r.status === 302,
});
res = http.get(`${BASE_URL}/owners/1/pets/1/visits/new`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.post(`${BASE_URL}/owners/1/pets/1/visits/new`, JSON.stringify({
description: 'Routine check-up',
}), {
headers: { 'Content-Type': 'application/json' },
});
check(res, {
'status is 302': (r) => r.status === 302,
});
});
sleep(0.5);
group('Vet API', () => {
let res = http.get(`${BASE_URL}/vets.html`);
check(res, {
'status is 200': (r) => r.status === 200,
});
res = http.get(`${BASE_URL}/vets`);
check(res, {
'status is 200': (r) => r.status === 200,
});
});
sleep(0.5);
}