Expand description
Drive socket events in a test, without a connection.
§What it runs, and what it can’t
It runs the same dispatch closure a live connection runs: the
payload is deserialized and validated the same way, the controller
is resolved from the same container, and the answer goes through
the same ack_result — captured instead of
sent. Nothing here reimplements the runtime, so what a test
observes is what a client would have received.
What it cannot do is be a connection. There is no
SocketRef, so:
- a handler that takes a
SocketRefreports that it needs a live socket rather than running —EmittedEvent::needs_socketsays so plainly; - a handshake middleware is built but not run, since running one means handing it a socket.
For those, and for anything protocol-level, use a real client. The socket-rooms verification script did exactly that, and is what demonstrated the wire behaviour this harness stands on.
ⓘ
let harness = SocketHarness::new(RoomController::socket_registration(&container), container);
let ack = harness.emit("join", json!({ "room": "general" })).await;
assert_eq!(ack.value()["room"], "general");
let bad = harness.emit("join", json!({ "room": "" })).await;
assert_eq!(bad.error_code(), Some("INVALID_PAYLOAD"));Structs§
- Emitted
Event - What an emitted event produced.
- Socket
Harness - Runs a controller’s events against a container, with no server.