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

Function testRateLimitAccuracy

benchmarks/rate-limiting.js:536–572  ·  view source on GitHub ↗

* Tests rate limiting accuracy under load

()

Source from the content-addressed store, hash-verified

534 * Tests rate limiting accuracy under load
535 */
536function testRateLimitAccuracy () {
537 console.log("\n📊 Rate Limiting Accuracy Test");
538 console.log("-".repeat(40));
539
540 const limit = 100;
541 const reset = 60;
542 const rateStore = new Map();
543 const clientId = "accuracy-test-client";
544
545 let allowed = 0;
546 let denied = 0;
547 const currentTime = Math.floor(Date.now() / 1000);
548
549 // Initialize client
550 rateStore.set(clientId, {
551 remaining: limit,
552 reset: currentTime + reset
553 });
554
555 // Make requests beyond the limit
556 for (let i = 0; i < limit + 50; i++) {
557 const state = rateStore.get(clientId);
558
559 if (state.remaining > 0) {
560 state.remaining--;
561 allowed++;
562 } else {
563 denied++;
564 }
565 }
566
567 console.log(`Rate limit accuracy (limit: ${limit}):`);
568 console.log(` Requests allowed: ${allowed}`);
569 console.log(` Requests denied: ${denied}`);
570 console.log(` Accuracy: ${allowed === limit ? "✅ Perfect" : "❌ Inaccurate"}`);
571 console.log(` Expected vs Actual: ${limit} vs ${allowed}`);
572}
573
574/**
575 * Main execution function

Callers 1

mainFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected