All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 4m58s
87 lines
2.7 KiB
JavaScript
87 lines
2.7 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://sonar-test-nest4.dev.svc.cluster.local:3000';
|
|
|
|
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('Health API', () => {
|
|
const res = http.get(`${targetUrl}/health`);
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
});
|
|
});
|
|
|
|
sleep(0.5);
|
|
|
|
group('Items API', () => {
|
|
const resGetAll = http.get(`${targetUrl}/api/items`);
|
|
check(resGetAll, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'body contains items': (r) => Array.isArray(JSON.parse(r.body)),
|
|
});
|
|
|
|
const resCreate = http.post(
|
|
`${targetUrl}/api/items`,
|
|
JSON.stringify({ name: 'Test Item', description: 'A test description' }),
|
|
{ headers: { 'Content-Type': 'application/json' } }
|
|
);
|
|
check(resCreate, {
|
|
'status is 201': (r) => r.status === 201,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'body contains id': (r) => JSON.parse(r.body).id !== undefined,
|
|
});
|
|
|
|
const itemId = JSON.parse(resCreate.body).id;
|
|
|
|
const resGetOne = http.get(`${targetUrl}/api/items/${itemId}`);
|
|
check(resGetOne, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'body contains correct item': (r) => JSON.parse(r.body).id === itemId,
|
|
});
|
|
|
|
const resUpdate = http.put(
|
|
`${targetUrl}/api/items/${itemId}`,
|
|
JSON.stringify({ name: 'Updated Item', description: 'Updated description' }),
|
|
{ headers: { 'Content-Type': 'application/json' } }
|
|
);
|
|
check(resUpdate, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'body contains updated item': (r) => JSON.parse(r.body).name === 'Updated Item',
|
|
});
|
|
|
|
const resDelete = http.del(`${targetUrl}/api/items/${itemId}`);
|
|
check(resDelete, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'body confirms deletion': (r) => JSON.parse(r.body).deleted === itemId,
|
|
});
|
|
});
|
|
|
|
sleep(0.5);
|
|
} |