Pause websocket traffic while using Selenium - selenium

While testing a single-page application where all page updating is done via JavaScript in conjunction with an active websocket connection, I have the need to test how user sessions handle disconnections and then re-connecting after X/Y/Z seconds.
What is the recommended approach for pausing websocket traffic?
I've tried modifying the network conditions of the driver (driver.set_network-conditions(offline=True)), but this does not stop the websocket traffic - it only prevents HTTP requests/responses - so that approach didn't work.

Related

Use websockets to update data from worker servers?

I have a server running expressjs that hosts the admin website and 4 to 10 additional worker servers that run a job scheduler and are constantly processing jobs and receiving new data. Is there a good way for the worker servers to notify the website server and then update the data on the website using websockets?
Worker servers can use any number of means for communicating with your main server. For example, you main server could have a special web server in your main server (not exposed to the outside world) that just receives http requests with data from the workers. So, whenever a worker gets new data, it just sends an http request to the main server.
Or, either webSocket or socket.io can be used server-to-server just fine (one end serves as the client for establishing the connection) and the other is the webSocket/socket.io server listening for incoming connections. In your case, the workers would be the clients and they would connection to your main server and then they can send data whenever they want over the webSocket or socket.io connection.
If you then want to automatically update data in various web browsers that have one of your pages open, those pages would also have a webSocket or socket.io connection open to your server so when your server gets new data, it could then tell the web page about it and the webpage could update its display without constantly refreshing/reloading a new page.
Either ws or socket.io can be used. Socket.io offers a number of features built on top of webSocket. You would choose socket.io if you want those added features. You can see a partial list of the added socket.io features here:
Moving from socket.io to raw websockets?

Issues with WebRTC based application

I have developed a WebRTC based application along with Kurento-Media-Server.
Problems with this application is:
It works but only on open network (i.e. if run on a network without firewall).
When in firewall it runs sometimes (once out of 10 attempts).
I have tried several things with the firewall, I have disabled all kind of incoming/outgoing traffic. I have created a port-forwarding for my application as well as Kurento-media server.
I am not sure how much useful this information might be but I am deploying my
application on the same physical box along with Kurento-Media-Server. I have configured google's STUN server on my client.js, I have also configured same STUN servers on kurento using code. I haven't configured TURN server.
Just confirming this, signaling server can be behind firewall along with rest of the application, correct?
I am not sure what to look for now, any help in this area would be great.
EDIT-1
From this link I learned that my current network on which my isn't working it has issues with plain websocket connection, it doesn't allow it, it only allows secure Websocket connections.
EDIT-2
Image of netscan:
In my phone network where my app works fine I see all greens in Websocket's "plain" column.
EDIT-3 Solved
Finally found the problem, We were using a router for testing and development and I found that the router had issues, I used LAN cable on the same router and everything worked fine. Calls from application were working just fine. Firewall related details help in configuring the firewall later on.
Based on your problem description it seems all the UDP traffic is not open in your firewall. WebRTC media run on UDP ports.As you mentioned it works one out of 10 times whch means only few UDP ports are open in your firewall.You are lucky when traffic comes via tose ports.You can open port-range in your firewall and configure the same in kurento-media-server config.Your job should be done.
Even if you configure TURN server you need to open certain ports for outgoing and incoming UDP traffic.For TURN server default port is 3478 or 8443 for sending data towards it but for incoming traffic you need to configure port-range on your TURN server and open those ports in your firewall. Always remember TURN server is assured way to connect but it's always costly.

Is there a way to combine websockets and normal http through apache?

So I have this server where I host more than one website for professional purposes. But I also like to develop game websites and I would like to create a roguelike game with HTML5.
The game engine itself would be developped in C++ on the server and the client should ask the server what changes in the environment after every move.
So, normally, I would send an ajax request to the server where apache would reroute the request to my C++ application which is running as a FastCGI Service. My C++ application would check the session, look up if the movement is valid, change the internal values so that the character moves, also changes other things in the environment, and would then send the changes back to the client.
But ajax requests can be relatively slow, opening and closing connections all the time. So when I read about websockets, I thought I was in heaven until I saw that it will interfere with Apache and Apache is not really optimized to work with it.
Obviously, I could create a web socket on a different port, but with all those firewalls out there, I don't think that's a good option.
So, is there a way to combine the two? Where apache is able to understand that a websocket request should be ignored and passed on to my application instead?

Simulate high load for an HTTP API client

I am writing a client for an HTTP API which is not yet publicly available.
Based on the specs I got, I have mocked a server which simulates the API, to test how my client reacts.
This server is a very simple Rack application, which currently runs on WEBRick.
The API client interacts with this fake API et performs correctly in the different tests cases.
Hopefully, I will just have to change the hostname in the config file when the API goes live.
However, I know for a fact that the API will be put under heavy load when it goes live. My client will thus most likely have to face :
HTTP timeouts
Jitter
Dropped TCP connections
503 Responses
...
I know that my client performs well in an ideal scenario, but how can I randomly (or not randomly) introduce these behaviors in my test cases, to verify that the client handles these errors correctly ?
Is there some kind of reverse proxy that can be configured to simulate these errors when serving data from a stable server on a stable network (in my case : local server on localhost) ?
You can try Net Limiter (http://www.netlimiter.com/) to shape bandwidth.
On the other hand, to make more accurate simulations you need to control both server and client side.
For instance, to simulate timeout condition your mock server can receive request from HTTP API client and then stop, hence triggering timeout on client side.
Other benefits of your own mock/test server is that you can emulate dropped TCP connections (just close newly received client connection), 50X responses, invalid responses, protocol breaking responses and much more.

All jmeter requests going to only one server with haproxy

I'm using Jmeter to load test my web application. I have two web servers and we are using HAProxy for load balance. All my tests are running fine and configured correctly. I have three jmeter remote clients so I can run my tests distributed. The problem I'm facing is that ALL my jmeter requests are only being processed by one of the web servers. For some reason it's not balancing and I'm having many time outs, and huge response times. I've looked around a lot for a way to make these requests being balanced, but I'm having no luck so far. Does anyone know what can be the cause of this behavior? Please let me know if you need to know anything about my environment first and I will provide the answers.
Check your haproxy configuration:
What is it's load balancing policy, if not round-robin is it based on ip source or some other info that might be common to your 3 remote servers?
Are you sure load balancing is working right? Try testing with browser first, if you can add some information about the web server in response to debug.
Check your test plan:
Are you sure you don't have somewhere in your requests a sessionid that is hardcoded?
How many threads did you configure?
In your Jmeter script by default the HTTP Request "Use KeepAlive" header option is checked.
Keep-Alive is a header that maintains a persistent connection between
client and server, preventing a connection from breaking
intermittently. Also known as HTTP keep-alive, it can be defined as a
method to allow the same TCP connection for HTTP communication instead
of opening a new connection for each new request.
This may cause all requests to go to the same server. Just uncheck the option and save, stop your script and re-run.