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.
Context
src/rateLimit.jswas added in #14 but has no tests.What to test
rateLimit:exceededevent with correctevent,limit,windowMs,retryAfterfieldswindowMselapses, the counter resets and messages pass through againeventsfilter option — rate limiting only applies to the specified events, others pass freelyonLimitReachedcallback is called instead of emittingrateLimit:exceededwhen providedSetup tip
Use
socket.io-clientwith a real server. To test window reset, advance time withDate.nowmocking or simply waitwindowMsms between bursts.