---
title: "Test WebSockets in Speedscale Cloud | Speedscale Docs"
description: "Capture a complete WebSocket session, replay it in a registered Kubernetes cluster, and read the handshake and message results in Speedscale Cloud."
canonical: "https://docs.speedscale.com/guides/websocket/cloud/"
---

[Documentation index](https://docs.speedscale.com/guides/llms.txt) | [Markdown](https://docs.speedscale.com/guides/websocket/cloud/index.md) | [Canonical page](https://docs.speedscale.com/guides/websocket/cloud/)

# 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](https://docs.speedscale.com/guides/capture/kubernetes/) configured for your test namespace. You can also [push the inbound recording from the proxymock guide](https://docs.speedscale.com/guides/websocket/cloud/#bring-a-local-recording).

<a id="deploy-the-demo"></a>

## 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.

```bash
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
```

<a id="capture-a-session-and-save-a-snapshot"></a>

## Capture a session and save a snapshot

1.  Start capture on the deployment. For eBPF capture, run:
    
    ```bash
    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](https://docs.speedscale.com/guides/capture/sidecar-namespaced/).
    
2.  After capture is active, run the client from another pod. The client connects through the demo's Kubernetes Service:
    
    ```bash
    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](https://docs.speedscale.com/guides/capture/filter/), 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](https://docs.speedscale.com/guides/capture/filter/#saving-traffic-). 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.

<a id="bring-a-local-recording"></a>

### Bring a local recording

If you followed [Test WebSockets with proxymock](https://docs.speedscale.com/guides/websocket/proxymock/), push its inbound recording and use the deployment in this guide as the replay target:

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

<a id="run-a-regression-replay"></a>

## 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:
    
    ```bash
    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](https://docs.speedscale.com/guides/replay/#run-your-first-dashboard-replay) and [readiness and report details](https://docs.speedscale.com/guides/reports/) for each step and the report views.

<a id="run-under-load"></a>

## 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](https://docs.speedscale.com/guides/replay/load-test/) 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.

<a id="mock-a-downstream-websocket"></a>

## 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](https://docs.speedscale.com/guides/replay/via-speedctl/#controlling-outbound-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](https://docs.speedscale.com/guides/websocket/).
