WebSocket Support

434 views
Skip to first unread message

Jeff Lage

unread,
Oct 15, 2015, 12:04:32 PM10/15/15
to mountebank-discuss
have you had any thoughts on how web sockets might fit in with mountebank?  for many of our web apps, though 90% of the API is HTTP, portions of it are delivered via web sockets and we'll need to mock those up also in test cycles.

Brandon Byars

unread,
Oct 15, 2015, 1:47:12 PM10/15/15
to Jeff Lage, mountebank-discuss
Good question. I'll play with it as soon as I get some time. I think it's just TCP but I'm not versed enough with them to have an intelligent answer yet :)

I definitely see how this could be useful.
-Brandon


On Thursday, October 15, 2015, Jeff Lage <jeff...@gmail.com> wrote:
have you had any thoughts on how web sockets might fit in with mountebank?  for many of our web apps, though 90% of the API is HTTP, portions of it are delivered via web sockets and we'll need to mock those up also in test cycles.

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Sent from Gmail Mobile

Brandon Byars

unread,
Nov 3, 2015, 11:17:23 PM11/3/15
to Jeff Lage, mountebank-discuss
Hi Jeff,
After poking at this for a little bit, it looks like this will have to be a separate protocol implementation in mountebank.  I've added it to the backlog and will get to it when I can - here's the issue: https://github.com/bbyars/mountebank/issues/77
-Brandon

Jeffrey Lage

unread,
Nov 4, 2015, 9:14:55 AM11/4/15
to Brandon Byars, mountebank-discuss
thanks for looking into it.

since we use socket.io currently, and it has the option to fall-back to HTTP long-polling when sockets are note available, we’re going to use that for stubs for now.  it does leave some gap that when we deploy that sockets might be ‘different’ in some way but it seems like a good place to start.

npisa...@gmail.com

unread,
Apr 11, 2017, 9:27:46 AM4/11/17
to mountebank-discuss, brando...@gmail.com
For the purposes of mocking websockets communication I'm considering using https://github.com/novnc/websockify in front of a Mb tcp imposter.
Has anybody tried a similar setup?

Cheers,
Nikolay

Nikolay Pisanchev

unread,
Apr 13, 2017, 8:16:41 AM4/13/17
to mountebank-discuss, brando...@gmail.com
FIY it seems to do the job without a hassle:

Given a simple tcp imposter on port 5555:

{
 
"protocol": "tcp",
 
"port": 5555,
 
"numberOfRequests": 0,
 
"mode": "text",
 
"requests": [],
 
"stubs": [
   
{
     
"responses": [
       
{
         
"is": {
           
"data": "somestring"
         
}
       
}
     
],
     
"predicates": []
   
}
 
],
 
"_links": {
   
"self": {
     
"href": "http://localhost:2525/imposters/5555"
   
}
 
}
}

and js websockify listening on 1234 and forwarding to 5555:

node websockify.js 1234 localhost:5555


when I run

const WebSocket = require('ws');

const ws = new WebSocket('ws://localhost:1234');

ws
.on('open', function open() {
  ws
.send('asdasdasd');
});


ws
.on('message', function incoming(data, flags) {
 console
.log(unescape(data));
});

Then I get 
somestring
as defined in the imposter on the console.


HTH,
Nikolay
Reply all
Reply to author
Forward
0 new messages