3.1 KiB
3.1 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | ||
|---|---|---|---|---|---|---|---|---|---|
| websocket-server-tests | Write tests for WebSocket server event target adapter | completed |
|
moderate | medium | component | implementation |
Description
Write tests for createWebSocketServerEventTarget. This requires mocking multiple WebSocket connections and simulating the fan-out behavior.
Test scenarios from the architecture doc:
- Topic-based fan-out — dispatchEvent sends only to connections subscribed to that event type
- Subscription protocol —
__subscribe/__unsubscribecontrol events correctly update the subscription map - Incoming aggregation — messages from any spoke dispatch to local listeners
- Connection add/remove — new connections are tracked, disconnections clean up all subscriptions
- Backpressure disconnect — slow consumers exceeding threshold are disconnected
- Backpressure callback —
onBackpressureis called before disconnecting - Direct messaging — events dispatched to
"direct:${spokeId}"reach only the target spoke - Mixed topology — server adapter and client adapters can communicate bidirectionally
Acceptance Criteria
test/event-target-websocket-server.test.tsexists and passes- Mock strategy for multiple WebSocket connections established
- Test:
addConnection/removeConnectiontrack connections correctly - Test:
__subscribecontrol event adds connection to topic's subscriber set - Test:
__unsubscribecontrol event removes connection from topic's subscriber set - Test:
dispatchEventsends only to connections subscribed to that topic - Test: connections NOT subscribed to a topic do NOT receive events for that topic
- Test: malformed JSON from spokes is silently ignored
- Test: invalid
__subscribewith empty/malformed topic is ignored - Test: backpressure threshold disconnect — connections exceeding
maxBufferedAmountare closed with code 1013 - Test:
onBackpressurecallback fires before disconnect - Test:
onConnectioncallback receives spoke target and WebSocket - Test:
onDisconnectioncallback fires on connection close - Test:
dispatchEventalways returnstrue - Test: send failure (ws.send throws) removes connection and fires
onDisconnection
References
- docs/architecture/event-targets/websocket-server.md (Test Plan section)
- src/event-target-websocket-server.ts
Notes
Completed as part of the websocket-server-adapter task. 46 test cases covering all acceptance criteria.
Summary
Tests were written alongside the adapter implementation. 46 tests pass, covering:
- Connection lifecycle (addConnection, removeConnection, automatic cleanup on close)
- Subscription protocol (__subscribe, __unsubscribe, idempotency, invalid topics)
- Topic-based fan-out (subscribed connections receive events, unsubscribed don't)
- Local listeners (addEventListener, removeEventListener, aggregation from spokes)
- Per-connection spoke targets (spoke.addEventListener, spoke.dispatchEvent)
- Error handling (malformed JSON, send failures, backpressure)
- Callbacks (onConnection, onDisconnection, onBackpressure)