feat(k6): add bespoke load test files
Some checks failed
SonarQube Analysis / Build, Test & Analyse (pull_request) Failing after 49s
Build and Push to ACR / Build and Push (push) Successful in 49s
Integration Test / Platform Conformance (pull_request) Successful in 3s
Integration Test / Unit Tests + Container Smoke (workflow_dispatch) All checks passed
Integration Test / Unit Tests + Container Smoke (pull_request) Successful in 41s
Some checks failed
SonarQube Analysis / Build, Test & Analyse (pull_request) Failing after 49s
Build and Push to ACR / Build and Push (push) Successful in 49s
Integration Test / Platform Conformance (pull_request) Successful in 3s
Integration Test / Unit Tests + Container Smoke (workflow_dispatch) All checks passed
Integration Test / Unit Tests + Container Smoke (pull_request) Successful in 41s
This commit is contained in:
88
k6/load-test.js
Normal file
88
k6/load-test.js
Normal file
@@ -0,0 +1,88 @@
|
||||
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-pyt2.dev.svc.cluster.local:8000';
|
||||
|
||||
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('Observability API', () => {
|
||||
const res = http.get(`${targetUrl}/health`);
|
||||
check(res, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'body contains status': (r) => r.json().status === 'UP',
|
||||
});
|
||||
});
|
||||
|
||||
sleep(0.5);
|
||||
|
||||
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,
|
||||
'body is an array': (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,
|
||||
'body 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,
|
||||
'body 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,
|
||||
'body 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,
|
||||
'body contains deleted id': (r) => r.json().deleted === itemId,
|
||||
});
|
||||
});
|
||||
|
||||
sleep(0.5);
|
||||
}
|
||||
Reference in New Issue
Block a user