Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate connection errors

We've been using protractor for end-to-end testing for a while.

Now we are trying to cover several corner cases, which involve modifying the response from the API endpoint requests - for this we are using protractor-http-mock which provides an easy-to-use way to replace HTTP responses with pre-defined mocks.

But, what if we want to test a situation when a sudden connection loss happens? What are our options in this case?

In other words, we want to achieve a case when requests to specific endpoints would produce a network connection error and see how our application would react.


I'm open to any suggestions, I am currently thinking of the following strategies:

  • see if there are third-party nodejs libraries similar to protractor-http-mock
  • mock $http angularjs service
  • fire up a proxy and somehow control it during the tests (grunt-connect-proxy looks pretty mature though I'm not sure if it is possible to dynamically change the behavior of the proxy from spec to spec)
  • control it on a browser level - e.g. with a Network Throttling google chrome feature (though I'm pretty sure it is something that selenium cannot control, Network throttling with chrome and selenium) (browser addon/extension?)
like image 712
alecxe Avatar asked Apr 01 '15 04:04

alecxe


People also ask

How do you simulate network errors?

Simulating a hard-down or node failure is fairly easy. All you have to do is turn off the node itself to verify how the system responds (system reconvergence). If high availability is enabled, a secondary/standby node will immediately take over and become the active node, servicing user requests.

How do I simulate a slow Internet connection on my iPhone?

Simulate Poor Network on iPhoneOpen the Settings app and navigate to the Developer option. Select the Network Link Conditioner under NETWORKING option. Now enable the Network Link Conditioner & choose the network profile you want, and start testing how your app works in different conditions.


1 Answers

Seems like the Comcast tool would provide the majority of the functionality you need:

Comcast is a tool designed to simulate common network problems like latency, bandwidth restrictions, and dropped/reordered/corrupted packets.

It works by wrapping up some system tools in a portable(ish) way. On BSD-derived systems such as OSX, we use tools like ipfw and pfctl to inject failure. On Linux, we use iptables and tc. Comcast is merely a thin wrapper around these controls.

https://github.com/tylertreat/Comcast

Example on Linux:

comcast --device=eth0 --latency=250 --target-bw=1000 --default-bw=1000000 --packet-loss=10% --target-addr=8.8.8.8,10.0.0.0/24 --target-proto=tcp,udp,icmp --target-port=80,22,1000:2000

You can change the settings on the fly and put packet loss up to 100% as needed.

like image 156
13rac1 Avatar answered Oct 04 '22 09:10

13rac1