| 283 | // ═══════════════════════════════════════════════════════════════════════════ |
| 284 | |
| 285 | async function testMemoryPressure(ctx: TestContext): Promise<void> { |
| 286 | console.log("\n═══ Test 5: Memory Pressure (Concurrent Large Requests) ═══\n"); |
| 287 | |
| 288 | try { |
| 289 | // Send 20 concurrent requests with 100KB payloads |
| 290 | const promises = Array.from({ length: 20 }).map(() => |
| 291 | fetch(`${ctx.proxy.baseUrl}/v1/chat/completions`, { |
| 292 | method: "POST", |
| 293 | headers: { "Content-Type": "application/json" }, |
| 294 | body: JSON.stringify({ |
| 295 | model: "deepseek/deepseek-chat", |
| 296 | messages: [{ role: "user", content: "x".repeat(100_000) }], // 100KB |
| 297 | }), |
| 298 | signal: AbortSignal.timeout(5000), |
| 299 | }).catch(() => null), |
| 300 | ); |
| 301 | |
| 302 | await Promise.all(promises); |
| 303 | await sleep(100); |
| 304 | |
| 305 | const health = await fetch(`${ctx.proxy.baseUrl}/health`); |
| 306 | assert(health.ok, "Proxy survived memory pressure (20x 100KB concurrent requests)"); |
| 307 | } catch (err) { |
| 308 | assert( |
| 309 | false, |
| 310 | `Memory pressure test failed: ${err instanceof Error ? err.message : String(err)}`, |
| 311 | ); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | // ═══════════════════════════════════════════════════════════════════════════ |
| 316 | // Main Test Runner |