* Tests with rate limiting enabled
()
| 342 | * Tests with rate limiting enabled |
| 343 | */ |
| 344 | async function rateLimitLoadTests () { |
| 345 | console.log("\n🔥 Rate Limiting Load Tests"); |
| 346 | console.log("=".repeat(50)); |
| 347 | |
| 348 | const server = createTestServer({ |
| 349 | rate: { |
| 350 | enabled: true, |
| 351 | limit: 50, // Low limit for testing |
| 352 | reset: 60, // 1 minute window |
| 353 | status: 429 |
| 354 | } |
| 355 | }); |
| 356 | |
| 357 | const startedServer = await startServer(server); |
| 358 | const baseUrl = `http://localhost:${startedServer.server.address().port}`; |
| 359 | |
| 360 | const tests = [ |
| 361 | { |
| 362 | title: "Rate Limit Test (Under Limit)", |
| 363 | url: `${baseUrl}/ping`, |
| 364 | connections: 5, |
| 365 | duration: 10 |
| 366 | }, |
| 367 | { |
| 368 | title: "Rate Limit Test (At Limit)", |
| 369 | url: `${baseUrl}/ping`, |
| 370 | connections: 20, |
| 371 | duration: 10 |
| 372 | }, |
| 373 | { |
| 374 | title: "Rate Limit Test (Over Limit)", |
| 375 | url: `${baseUrl}/ping`, |
| 376 | connections: 50, |
| 377 | duration: 10 |
| 378 | } |
| 379 | ]; |
| 380 | |
| 381 | const results = []; |
| 382 | for (const test of tests) { |
| 383 | const result = await runLoadTest(test); |
| 384 | results.push({ ...test, result }); |
| 385 | |
| 386 | await new Promise(resolve => setTimeout(resolve, 2000)); // Longer pause for rate limit reset |
| 387 | } |
| 388 | |
| 389 | startedServer.stop(); |
| 390 | |
| 391 | return results; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Stress tests with very high load |
no test coverage detected