Example on how to use and test websockets (v0.5) #2836
Replies: 1 comment
-
Sadly, this isn't possible right now, because Rocket doesn't expose the upgrade mechanism to tests. I'm going to close this, and open an issue for this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am looking for more documentation on how to use and test websockets using the rocket_ws crate. Primarily I want to know how to setup a unit test for a route I have defined that takes a WebSocket, and returns either a Channel, or a Stream. All of the examples in the rocket_ws api docs involve creating Rocket routes, but there are no example on how to test these.
I know the standard http request way of testing a route is to:
I am unsure how to move forward with this using WebSockets though. How can I create an instance of a WebSocket as a client, which I can use to interact with the WebSocket that the server spawns in response to the associated route being called.
For example, I want to write a function to test this route:
Are we expected to create an initial HTTP request with the appropriate upgrade header ourselves, and send the request to create the WebSocket? Even then, how would we go about doing this given the WebSocket 'new' method is private.
If example code could be provided I would be very grateful. I have spent many hours looking over both github and the official docs and could not find anything like this.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions