Skip to content

test: add tests for rate limiter #18

Description

@Aaromalpm

Context

src/rateLimit.js was added in #14 but has no tests.

What to test

  • Messages within the limit pass through normally
  • The (limit + 1)th message within the window is blocked
  • Client receives rateLimit:exceeded event with correct event, limit, windowMs, retryAfter fields
  • After windowMs elapses, the counter resets and messages pass through again
  • events filter option — rate limiting only applies to the specified events, others pass freely
  • onLimitReached callback is called instead of emitting rateLimit:exceeded when provided
  • Rate limit state is cleaned up from memory after socket disconnects

Setup tip

Use socket.io-client with a real server. To test window reset, advance time with Date.now mocking or simply wait windowMs ms between bursts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions