Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Test Server #46

Open
dpick opened this issue Dec 30, 2017 · 4 comments
Open

Expose Test Server #46

dpick opened this issue Dec 30, 2017 · 4 comments

Comments

@dpick
Copy link

dpick commented Dec 30, 2017

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.

@Azolo
Copy link
Owner

Azolo commented 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
Copy link
Owner

Azolo commented 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
Copy link
Author

dpick commented 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
Copy link

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 :)

Thank you so much for the awesome library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants