question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocket support for Mock engine

See original GitHub issue

Subsystem Client (Mock engine), WebSocket

Is your feature request related to a problem? Please describe. Currently there is no WebSocket support for the Mock engine on the client part. This could be particularly useful when testing clients that interact with WebSockets.

Describe the solution you’d like I think there should be a method inside the Mock engine that allows to setup a proper WebSocket mock. This could be something like

private val client = HttpClient(MockEngine) {
    engine {
        addWebSocketHandler(host = "localhost", port = 8080, path = "/ws") { incoming, outgoing ->

        }
    }
}

Motivation to include to ktor This feature could be useful to all the people that want to test a client that interacts with a websocket without having to spin one up.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
shaunekcommented, Mar 19, 2022

@e5l This issue seems to be about websocket client testing, and you closed this issue out mentioning it is supported with the withTestApplication function… I could be missing something but withTestApplication seems to be pretty focused on the ktor server testing as it requires an Application.method to be provided. I looked and couldn’t find any client-only focused mock engines that support websockets. The current docs (v1.6) still recommend using MockEngine with HttpClient, but MockEngine doesn’t seem to support websockets as far as I can tell.

Are you aware of any client-only websocket testing library besides OkHTTP’s MockWebServer? If so can you please point me in the right direction? For context, I have JVM-hosted websocket client that needs to consume a third party service over websockets and I’m not finding helpful examples that are unit testable. I was hoping to find something that doesn’t require running a server to test the client code - something similar to ktor’s HttpClient+MockEngine that makes it possible to test client code without running a server.

If you aren’t aware of any libraries fitting my description I wonder if it could be helpful to reopen this issue?

1reaction
oleg-larshincommented, Aug 10, 2020

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest-websocket-mock - npm
jest-websocket-mock exposes a WS class that can instantiate mock websocket servers that keep track of the messages they receive, and in turn can ......
Read more >
The WebSocket API (WebSockets) - Web APIs - MDN Web Docs
desktop desktop Chrome Edge WebSocket Full support. Chrome4. Toggle history Full support. Edge12. Toggl... WebSocket() constructor Full support. Chrome4. Toggle history Full support. Edge12. Toggl...
Read more >
Is there any way to mock a request for websocket
I am writing a test method to verify the application removing all the external dependencies. I am using Fiddler to intercept the request...
Read more >
Testing Sails sockets using Jest - Medium
This web app uses Sails to handle requests and sockets. Sails uses SocketIO behind the scenes, and I found this library jest-websocket-mock ......
Read more >
Socket.IO
In most cases, the connection will be established with WebSocket, providing a low-overhead communication channel between the server and the client.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found