testing/testing_rate_limiter.ts

Test-only RateLimiter subclass with bucket tracking + reset_all.

Production code never instantiates this; test binaries swap it in for production RateLimiter so _testing_reset can clear every bucket between cases. Mirrors the TestingArgon2idHasher pattern from the Rust spine — same call surface as the production class, plus test-only knobs (reset_all, tracked_keys).

Constructor + every overridden method preserve production semantics by delegating to super.* after tracking; reset_all walks the tracked-keys set and calls super.reset per entry. Tests that depend on burst behavior get identical results between production and test instantiations.

Usage in a test binary:

import {TestingRateLimiter} from '@fuzdev/fuz_app/testing/testing_rate_limiter.ts'; const limiter = new TestingRateLimiter(default_login_ip_rate_limit); await create_app_server({backend, ip_rate_limiter: limiter, ...}); // Inside the `_testing_reset` handler's `reset_state`: limiter.reset_all();
view source

Declarations
#

TestingRateLimiter
#

testing/testing_rate_limiter.ts view source

import {TestingRateLimiter} from '@fuzdev/fuz_app/testing/testing_rate_limiter.js';

RateLimiter plus bucket tracking. Every check/record call adds its key to #seen_keys; reset removes it; reset_all clears every tracked bucket. Drop-in replacement anywhere a RateLimiter is expected — the type is nominally compatible via subclassing.

inheritance

extends: RateLimiter

check

type (key: string, now?: number | undefined): RateLimitResult

key

type string

now?

type number | undefined
optional

record

type (key: string, now?: number | undefined): RateLimitResult

key

type string

now?

type number | undefined
optional

reset

type (key: string): void

key

type string
returns void

reset_all

Clear every bucket this limiter has been asked about. Idempotent; safe to call before any check/record activity. Designed to be invoked from a _testing_reset handler's reset_state callback so the test binary's rate-limit buckets don't leak across test cases.

type (): void

returns void

tracked_keys

Snapshot of every bucket key this limiter has observed via check/record. Doesn't reflect post-cleanup pruning — keys that cleanup() removed remain in tracked_keys until reset/reset_all runs (or the limiter is disposed). Useful for assertions like "limiter saw exactly N IPs" in tests.

type ReadonlySet<string>

getter

Depends on
#