feat(k6): add bespoke load test files
All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 1m22s

This commit is contained in:
2026-05-07 20:35:53 +00:00
parent 6abc6d3957
commit d0f69f3582
3 changed files with 168 additions and 0 deletions

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

@@ -0,0 +1,90 @@
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://test-for-310--005.dev.svc.cluster.local:8080';
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'],
},
};
http.setResponseCallback(http.expectedStatuses({ min: 200, max: 399 }));
export default function () {
group('Items API', () => {
const listRes = http.get(`${targetUrl}/api/items`);
check(listRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains items': (r) => Array.isArray(r.json()),
});
const createRes = http.post(`${targetUrl}/api/items`, JSON.stringify({ name: 'Test Item', description: 'A test item description' }), {
headers: { 'Content-Type': 'application/json' },
});
check(createRes, {
'status is 201': (r) => r.status === 201,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains id': (r) => r.json().id !== undefined,
});
const itemId = createRes.json().id;
const getRes = http.get(`${targetUrl}/api/items/${itemId}`);
check(getRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains correct id': (r) => r.json().id === itemId,
});
const updateRes = http.put(`${targetUrl}/api/items/${itemId}`, JSON.stringify({ name: 'Updated Item', description: 'Updated description' }), {
headers: { 'Content-Type': 'application/json' },
});
check(updateRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains updated name': (r) => r.json().name === 'Updated Item',
});
const deleteRes = http.del(`${targetUrl}/api/items/${itemId}`);
check(deleteRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response confirms deletion': (r) => r.json().deleted === itemId,
});
});
sleep(0.5);
group('Actuator API', () => {
const healthRes = http.get(`${targetUrl}/actuator/health`);
check(healthRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'response contains UP status': (r) => r.json().status === 'UP',
});
const prometheusRes = http.get(`${targetUrl}/actuator/prometheus`);
check(prometheusRes, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
});
sleep(0.5);
}