A complete WebSocket testing suite designed for testing load balancing strategies with WebSocket connections. This tool helps validate that load balancers properly distribute WebSocket connections across multiple server instances and maintain session affinity when required.
The suite includes both server and client components written in Go. The server provides WebSocket connections with identification and statistics, while the client offers an interactive terminal UI for testing multiple concurrent connections and observing load distribution.
- WebSocket Endpoint (
/ws): Accepts WebSocket connections and sends server identification - HTTP Status Endpoint (
/): Returns JSON with server ID and connected client count - Kubernetes Support: Automatically detects pod name when running in Kubernetes
- Client Tracking: Thread-safe tracking of concurrent WebSocket connections
- Ping/Pong Support: Configurable heartbeat mechanism with timeout handling
- Interactive Terminal UI: Real-time dashboard showing connection status and server information
- Multi-Connection Support: Test with multiple concurrent connections
- Server Aggregation: Groups connections by server ID for easy monitoring
- Connection Logging: Real-time message and event logging
- Configurable Options: Customizable endpoints, timeouts, and headers
The service identifies itself using the first available option:
POD_NAMEenvironment variable (set by Kubernetes)HOSTNAMEenvironment variable- System hostname
- Fallback to generated UUID (e.g., "a1b2c3d4-e5f6-4789-8abc-def012345678")
Connects via WebSocket and receives JSON messages:
{
"type": "welcome|status",
"server_id": "pod-name-12345",
"timestamp": "2025-08-07T10:30:00Z",
"clients": 3
}Returns current server status:
{
"type": "status",
"server_id": "pod-name-12345",
"timestamp": "2025-08-07T10:30:00Z",
"clients": 3
}cd server
go run main.goServer starts on port 8080 (configurable via PORT environment variable).
PORT: Server port (default: 8080)POD_NAME: Pod name in Kubernetes (auto-detected)PING_INTERVAL: WebSocket ping interval (default: 30s)PONG_TIMEOUT: Pong response timeout (default: 10s)DEBUG: Enable debug mode to log client headers (default: false)
cd client
go run main.go# Basic usage
go run main.go --endpoint ws://localhost:8080/ws
# Multiple connections
go run main.go --connections 5 --endpoint ws://your-server:8080/ws
# Custom headers and timeouts
go run main.go --header "Authorization: Bearer token" --timeout 30s --read-timeout 120s--endpoint: WebSocket server endpoint (default: ws://localhost:8080/ws)--connections: Number of concurrent connections (default: 1)--timeout: Connection timeout (default: 10s)--read-timeout: Read timeout for messages (default: 60s)--header, -H: Custom headers (format: 'Key: Value', can be used multiple times)
All CLI options can be set via environment variables with WS_ prefix:
WS_ENDPOINTWS_CONNECTIONSWS_TIMEOUTWS_READ_TIMEOUTWS_HEADERS
qorCtrl+C: Quit the applicationr: Reconnect all connectionsc: Clear message logs
Build and run:
docker build -t ws-server .
docker run -p 8080:8080 ws-serverDeploy to Kubernetes:
kubectl apply -f k8s/This creates:
- 3 replica deployment with pod identification
- LoadBalancer service exposing port 80
- Health checks and resource limits
# Check status endpoint
curl http://localhost:8080/
# WebSocket test with wscat
wscat -c ws://localhost:8080/wsThe included client provides the best testing experience:
cd client
go run main.go --connections 3 --endpoint ws://localhost:8080/wsThis will show a real-time dashboard with:
- Connection status for each server
- Message logs and ping/pong activity
- Server-reported client counts
- Terminal-based interface with live updates