All checks were successful
Build and Push to ACR / Build and Push (push) Successful in 1m16s
97 lines
3.0 KiB
JavaScript
97 lines
3.0 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://test-for-310--007.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', () => {
|
|
// List all items
|
|
let res = http.get(`${targetUrl}/api/items`);
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'response contains items': (r) => Array.isArray(r.json()),
|
|
});
|
|
|
|
// Create a new item
|
|
res = http.post(`${targetUrl}/api/items`, JSON.stringify({ name: 'Test Item', description: 'A test item description' }), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
check(res, {
|
|
'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 = res.json().id;
|
|
|
|
// Get single item
|
|
res = http.get(`${targetUrl}/api/items/${itemId}`);
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'response contains correct id': (r) => r.json().id === itemId,
|
|
});
|
|
|
|
// Update item
|
|
res = http.put(`${targetUrl}/api/items/${itemId}`, JSON.stringify({ name: 'Updated Item', description: 'Updated description' }), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
check(res, {
|
|
'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',
|
|
});
|
|
|
|
// Delete item
|
|
res = http.del(`${targetUrl}/api/items/${itemId}`);
|
|
check(res, {
|
|
'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', () => {
|
|
// Health check
|
|
let res = http.get(`${targetUrl}/actuator/health`);
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
'response contains status UP': (r) => r.json().status === 'UP',
|
|
});
|
|
|
|
// Prometheus metrics
|
|
res = http.get(`${targetUrl}/actuator/prometheus`);
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
});
|
|
});
|
|
|
|
sleep(0.5);
|
|
} |