You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to write unit tests around my web socket message handling and I haven't been able to think of a good way to assert on the response my code sends back to the socket. It looks like in the tests for websockex you implement a fake server and connect a client to it to test things. Could you expose that server so that consumers of their library can make use of it as well?
I'm also open to other suggestions as well if anyone has other ideas.
Hmm, so there's nothing "fake" about the server. It's a full blown Plug/Cowboy server that I start an instance of before each test that starts at a random port in the 50k-63k range. If the port is in use then I go to the next port.
I could extract the root of that out into a Bare WebSocket Server, but it may be easier just to write up something on how to do it yourself. Let me think on it.
Also, incase you were wondering, the overhead of starting a actual server is almost nothing. The WebSockex test suite run in like 4 seconds, and if I were to take the WebSocket properly closing to spec tests out it would probably be more like < 1 second.
👍 I'm actually much more comfortable spinning up a real server rather than mocking it out as well. An example of how to test something that uses WebSockex would probably be useful for people though. At least it would be for me 😄 .
Reacted by Alex Kwiatkowski, Sebastian Seilund, Zacck Osiemo and Wiktor Obrębski
Would it be possible to expose|document this in such a way that it is usable like the Tesla.Mock.
This way developers can quickly setup Mocks and use them to do integration testing when using the library .... If it's possible and would need work ... I have hands to offer :)
Activity
Azolo commentedon Dec 30, 2017
Hmm, so there's nothing "fake" about the server. It's a full blown Plug/Cowboy server that I start an instance of before each test that starts at a random port in the 50k-63k range. If the port is in use then I go to the next port.
https://github.com/Azolo/websockex/blob/master/test/support/test_server.ex
I could extract the root of that out into a Bare WebSocket Server, but it may be easier just to write up something on how to do it yourself. Let me think on it.
Azolo commentedon Dec 30, 2017
Also, incase you were wondering, the overhead of starting a actual server is almost nothing. The WebSockex test suite run in like 4 seconds, and if I were to take the WebSocket properly closing to spec tests out it would probably be more like < 1 second.
dpick commentedon Dec 30, 2017
👍 I'm actually much more comfortable spinning up a real server rather than mocking it out as well. An example of how to test something that uses WebSockex would probably be useful for people though. At least it would be for me 😄 .
zacck-zz commentedon Dec 25, 2018
Would it be possible to
expose|documentthis in such a way that it is usable like the Tesla.Mock.This way developers can quickly setup Mocks and use them to do integration testing when using the library .... If it's possible and would need work ... I have hands to offer :)
Thank you so much for the awesome library