Files
crawlapi/load-tests/load.js
Developer 62994d4f3d
Some checks failed
CI / Test (push) Has been cancelled
Deploy / Deploy to Staging (push) Has been cancelled
CI / Build & Push (push) Has been cancelled
Deploy / Deploy to Production (push) Has been cancelled
Initial commit: Full Crawl API implementation
2026-04-29 07:03:48 +00:00

44 lines
1.1 KiB
JavaScript

import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 10 }, // Ramp up
{ duration: '5m', target: 10 }, // Steady state
{ duration: '2m', target: 20 }, // Ramp up more
{ duration: '5m', target: 20 }, // Steady state
{ duration: '2m', target: 0 }, // Ramp down
],
thresholds: {
http_req_duration: ['p(95)<5000'], // 95% of requests under 5s
http_req_failed: ['rate<0.1'], // Less than 10% errors
},
};
const API_URL = __ENV.API_URL || 'http://localhost:3000';
const API_KEY = __ENV.API_KEY || 'test-key';
const endpoints = ['content', 'json', 'links'];
export default function () {
const endpoint = endpoints[Math.floor(Math.random() * endpoints.length)];
const res = http.post(
`${API_URL}/api/${endpoint}`,
JSON.stringify({ url: 'https://example.com' }),
{
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
}
);
check(res, {
'status is 200': (r) => r.status === 200,
'response has success': (r) => r.json('success') === true,
});
sleep(1);
}