Initial commit: Full Crawl API implementation
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

This commit is contained in:
2026-04-29 07:03:48 +00:00
commit 62994d4f3d
92 changed files with 6176 additions and 0 deletions

43
load-tests/load.js Normal file
View File

@@ -0,0 +1,43 @@
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);
}

13
load-tests/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "crawlapi-load-tests",
"version": "1.0.0",
"scripts": {
"smoke": "k6 run smoke.js",
"load": "k6 run load.js",
"stress": "k6 run stress.js",
"screenshot": "k6 run screenshot.js"
},
"devDependencies": {
"@types/k6": "^0.52.0"
}
}

37
load-tests/screenshot.js Normal file
View File

@@ -0,0 +1,37 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 5,
duration: '3m',
thresholds: {
http_req_duration: ['p(95)<30000'], // Screenshots take longer
},
};
const API_URL = __ENV.API_URL || 'http://localhost:3000';
const API_KEY = __ENV.API_KEY || 'test-key';
export default function () {
const res = http.post(
`${API_URL}/api/screenshot`,
JSON.stringify({
url: 'https://example.com',
options: { fullPage: true }
}),
{
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,
'response has url': (r) => r.json('data.url') !== undefined,
});
sleep(2);
}

28
load-tests/smoke.js Normal file
View File

@@ -0,0 +1,28 @@
import http from 'k6/http';
import { check } from 'k6';
export const options = {
vus: 1,
duration: '1m',
};
const API_URL = __ENV.API_URL || 'http://localhost:3000';
const API_KEY = __ENV.API_KEY || 'test-key';
export default function () {
const res = http.post(
`${API_URL}/api/content`,
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,
});
}

40
load-tests/stress.js Normal file
View File

@@ -0,0 +1,40 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 50 },
{ duration: '5m', target: 50 },
{ duration: '2m', target: 100 },
{ duration: '5m', target: 100 },
{ duration: '2m', target: 200 },
{ duration: '5m', target: 200 },
{ duration: '2m', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<10000'],
http_req_failed: ['rate<0.2'],
},
};
const API_URL = __ENV.API_URL || 'http://localhost:3000';
const API_KEY = __ENV.API_KEY || 'test-key';
export default function () {
const res = http.post(
`${API_URL}/api/content`,
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,
});
sleep(Math.random() * 2);
}