MCPcopy Create free account
hub / github.com/avoidwork/tenso / testMemoryLeaks

Function testMemoryLeaks

benchmarks/memory.js:412–498  ·  view source on GitHub ↗

* Tests memory leaks in long-running scenarios

()

Source from the content-addressed store, hash-verified

410 * Tests memory leaks in long-running scenarios
411 */
412async function testMemoryLeaks () {
413 console.log("🔥 Memory Leak Detection Test");
414 console.log("-".repeat(50));
415
416 const monitor = new MemoryMonitor();
417 const server = tenso({
418 port: 0,
419 silent: true,
420 logging: { enabled: false },
421 auth: { protect: [] },
422 rate: { enabled: true, limit: 1000 },
423 security: { csrf: false }
424 });
425
426 server.get("/test", (req, res) => {
427 res.send({
428 data: Array.from({ length: 100 }, (_, i) => ({ id: i, value: Math.random() })),
429 timestamp: Date.now()
430 });
431 });
432
433 monitor.snapshot("Initial state");
434
435 // Run multiple cycles to detect leaks
436 const cycles = 5;
437 const requestsPerCycle = 500;
438
439 for (let cycle = 0; cycle < cycles; cycle++) {
440 for (let i = 0; i < requestsPerCycle; i++) {
441 const req = {
442 method: "GET",
443 url: "/test",
444 headers: { accept: "application/json" },
445 parsed: { searchParams: new URLSearchParams() },
446 server: server,
447 sessionID: `session-${cycle}-${i}`,
448 ip: `192.168.1.${i % 255}`
449 };
450
451 const res = {
452 statusCode: 200,
453 headers: {},
454 getHeader: name => res.headers[name],
455 removeHeader: name => delete res.headers[name],
456 header: (name, value) => res.headers[name] = value, // eslint-disable-line no-return-assign
457 getHeaders: () => res.headers
458 };
459
460 // Simulate request processing
461 server.render(req, res, { message: "test", cycle, iteration: i });
462 server.rateLimit(req);
463 }
464
465 monitor.snapshot(`After cycle ${cycle + 1} (${requestsPerCycle} requests)`);
466 }
467
468 monitor.report();
469

Callers 1

mainFunction · 0.85

Calls 8

snapshotMethod · 0.95
reportMethod · 0.95
diffMethod · 0.95
formatBytesMethod · 0.95
tensoFunction · 0.90
logMethod · 0.80
renderMethod · 0.80
rateLimitMethod · 0.80

Tested by

no test coverage detected