test: strengthen launch smoke and capacity guardrails

This commit is contained in:
Codex
2026-07-01 04:10:55 +08:00
parent 3d33c783cd
commit 6bdb2a175a
11 changed files with 494 additions and 39 deletions

View File

@@ -9,6 +9,7 @@ const matrix = [
{ name: 'read-30', duration: 120, concurrency: 30, ramp: 15, writes: false, ratio: 0 },
{ name: 'mixed-50', duration: 60, concurrency: 50, ramp: 10, writes: true, ratio: 0.1 },
{ name: 'mixed-100', duration: 60, concurrency: 100, ramp: 15, writes: true, ratio: 0.08 },
{ name: 'mixed-150', duration: 60, concurrency: 150, ramp: 20, writes: true, ratio: 0.06 },
];
function run(command, args, options = {}) {
@@ -44,25 +45,32 @@ function latestBenchmarkJson(before) {
return path.relative(repoRoot, files[0]).replaceAll('\\', '/');
}
function waitForHealth(timeoutMs = 60_000) {
const started = Date.now();
while (Date.now() - started < timeoutMs) {
const result = spawnSync(process.execPath, ['-e', `fetch('${apiBase}/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))`], {
cwd: repoRoot,
stdio: 'ignore',
shell: process.platform === 'win32',
});
if (result.status === 0) return;
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1000);
}
throw new Error(`API did not become healthy at ${apiBase}`);
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function main() {
async function waitForHealth(timeoutMs = 120_000) {
const started = Date.now();
let lastError = null;
while (Date.now() - started < timeoutMs) {
try {
const response = await fetch(`${apiBase}/health`);
const payload = await response.json().catch(() => ({}));
if (response.ok && payload.ok) return;
lastError = new Error(`HTTP ${response.status}: ${JSON.stringify(payload)}`);
} catch (error) {
lastError = error;
}
await sleep(1000);
}
throw new Error(`API did not become healthy at ${apiBase}. ${lastError?.message || ''}`);
}
async function main() {
const generated = [];
try {
run('docker', ['compose', '-f', 'docker-compose.api.yml', '-f', 'docker-compose.api.benchmark.yml', 'up', '-d', '--build', 'api']);
waitForHealth();
await waitForHealth();
for (const item of matrix) {
const before = Date.now();
run('node', ['scripts/api-performance-benchmark.js'], {
@@ -92,4 +100,7 @@ function main() {
}
}
main();
main().catch(error => {
console.error(error);
process.exitCode = 1;
});