Skip to content

Add WebSocket backpressure tests for slow clients in src/ws/hub.ts #246

@Jagadeeshftw

Description

@Jagadeeshftw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programbackendBackend service workperformancePerformance / cachingtestingTests and coverage

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions