Skip to main content

Test WebSockets in Speedscale Cloud

Capture a short WebSocket exchange from a Kubernetes workload and save it as a snapshot. Use that snapshot to check a new version of the service or to replay many concurrent connections. The demo sends a welcome message, echoes a client message as JSON, and ends with a clean close.

Use a Kubernetes cluster registered with Speedscale Cloud, with traffic capture configured for your test namespace. You can also push the inbound recording from the proxymock guide.

Deploy the demo​

Run these commands in a test namespace watched by the Speedscale operator. The sample deployment installs its WebSocket dependency from the npm registry when it starts. Set DEMO_NAMESPACE to your test namespace.

export DEMO_NAMESPACE=default
curl -fsSLO https://docs.speedscale.com/examples/browser-websocket/demo.mjs
curl -fsSLO https://docs.speedscale.com/examples/browser-websocket/demo.yaml
curl -fsSLO https://docs.speedscale.com/examples/browser-websocket/socket-client.mjs

kubectl -n "$DEMO_NAMESPACE" create configmap browser-ws-demo --from-file=demo.mjs
kubectl -n "$DEMO_NAMESPACE" apply -f demo.yaml
kubectl -n "$DEMO_NAMESPACE" rollout status deployment/browser-ws-demo

Capture a session and save a snapshot​

  1. Start capture on the deployment. For eBPF capture, run:

    kubectl -n "$DEMO_NAMESPACE" annotate deployment/browser-ws-demo \
    capture.speedscale.com/enabled=true --overwrite

    For a namespace-scoped sidecar installation, use the sidecar capture workflow.

  2. After capture is active, run the client from another pod. The client connects through the demo's Kubernetes Service:

    kubectl -n "$DEMO_NAMESPACE" run browser-ws-client --rm -i --restart=Never \
    --image=node:22-alpine --command -- \
    node --input-type=module - ws://browser-ws-demo:8080/ws < socket-client.mjs
  3. In the deployment's Traffic Viewer, narrow the time range to the exchange. Check that the capture includes the 101 upgrade and the following client and server messages. A Frame badge identifies a message row without an HTTP status. Open the rows to inspect their direction and contents.

  4. Save the traffic as a snapshot. Keep the upgrade, messages, and close together. Traffic captured from the service's perspective should be inbound for this replay.

Coding agent prompt

In the designated test namespace, deploy the demo and capture one complete inbound WebSocket session from the client pod. Check that the upgrade and both message directions are present before preparing the snapshot.

Bring a local recording​

If you followed Test WebSockets with proxymock, push its inbound recording and use the deployment in this guide as the replay target:

proxymock cloud push snapshot --in ./socket-inbound --name websocket-demo

Run a regression replay​

  1. Open the snapshot in the dashboard and select Replay. On the replay page, pick the registered cluster and the demo's namespace in step 1, and a regression test under API Contract and Correctness in step 2.

  2. In step 3, check that the inbound traffic goes to the demo service at http://browser-ws-demo.<namespace>:8080. If the snapshot came from a local recording, use the pencil to set this target.

  3. Select Start Replay and open the report. In Accuracy, inspect the handshake and server messages. Use the details to compare the recorded response with the live one.

  4. Change the demo's reply, leaving the original snapshot in place:

    kubectl -n "$DEMO_NAMESPACE" set env deployment/browser-ws-demo REGRESSION=1
    kubectl -n "$DEMO_NAMESPACE" rollout status deployment/browser-ws-demo
  5. Run the same replay. The handshake still succeeds and the welcome still matches. The recorded echo's text is check; the changed service replies changed. Inspect that response difference in the report.

See the replay page and readiness and report details for each step and the report views.

Run under load​

Restore the original reply with kubectl -n "$DEMO_NAMESPACE" set env deployment/browser-ws-demo REGRESSION- and wait for the rollout. On the replay page, pick a test under Performance and Stress in step 2, or a load test config with a short, low-concurrency stage, against the same test service. Use virtual-user stages, so each virtual user opens its own connection and replays whole sessions, handshake first. A message replayed without its handshake fails with no open WebSocket session. Start the replay with the original snapshot and compare upgrade latency, message failures, and timeouts with the single-user regression run. Each message counts as a request and there is no separate connection count, so read request rates against the number of messages in a recorded session.

Mock a downstream WebSocket​

When the workload under test is the WebSocket client, capture that workload's complete outbound exchange. Include it in the replay snapshot, then keep the dependency attached in step 4 of the replay page, Attach mock services. The responder accepts the client's upgrade, sends the recorded server messages, and checks the client's messages in session order. See replay with mocks for workload-level mock selection.

Coding agent prompt

Prepare a regression replay and a small load replay using the same WebSocket snapshot. Compare the report's upgrade, server messages, and failures before and after changing the demo reply.

For frame details and troubleshooting, see WebSocket Testing.

Loading search...