Description
src/ws/hub.ts implements backpressure handling for slow WebSocket clients but this logic is untested. A slow client that cannot drain its send buffer fast enough could cause memory growth or event drops that are invisible in the current test suite. Dedicated backpressure tests must be added that simulate slow consumers and assert that StreamHub applies the documented drop/queue behaviour correctly.
Requirements and context
- Write tests that connect a
ws client with an artificially throttled socket.drain to simulate a slow consumer
- Assert that
StreamHub emits a backpressure event or drops messages according to its documented policy when ws.bufferedAmount exceeds the configured threshold
- Assert that fast clients on the same hub are not affected by a slow peer
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/ws-backpressure-tests
Implement changes
- Update/Write:
tests/ws/hub.backpressure.test.ts — slow-client simulation tests
- Update/Write:
tests/ws/fixtures/slowClient.ts — throttled WebSocket test client helper
- Update/Write:
src/ws/hub.ts — add/document backpressure event emission if not already present
- Add documentation:
docs/websocket.md — document backpressure policy and configuration
- Include clear code comments and types
- Validate security assumptions
Test and commit
- Run tests:
pnpm test (or pnpm test:coverage)
- Cover edge cases: single slow client, multiple slow clients, slow client alongside fast client, client that recovers from backpressure, client disconnection during backpressure
- Include test output and security notes
Example commit message
test: add WebSocket backpressure tests for slow clients in StreamHub
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
src/ws/hub.tsimplements backpressure handling for slow WebSocket clients but this logic is untested. A slow client that cannot drain its send buffer fast enough could cause memory growth or event drops that are invisible in the current test suite. Dedicated backpressure tests must be added that simulate slow consumers and assert thatStreamHubapplies the documented drop/queue behaviour correctly.Requirements and context
wsclient with an artificially throttledsocket.drainto simulate a slow consumerStreamHubemits abackpressureevent or drops messages according to its documented policy whenws.bufferedAmountexceeds the configured thresholdSuggested execution
Fork the repo and create a branch
Implement changes
tests/ws/hub.backpressure.test.ts— slow-client simulation teststests/ws/fixtures/slowClient.ts— throttled WebSocket test client helpersrc/ws/hub.ts— add/documentbackpressureevent emission if not already presentdocs/websocket.md— document backpressure policy and configurationTest and commit
pnpm test(orpnpm test:coverage)Example commit message
Guidelines