Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to simulate connection timeout using wiremock tools?

Tags:

I know that it can simulate SocketTimeoutException by using withFixedDelay, but what about ConnectionTimeoutException?

like image 432
Developer87 Avatar asked May 11 '15 10:05

Developer87


2 Answers

Yes it is possible to do this with WireMock by calling addDelayBeforeProcessingRequests(300) against the Java API or posting the following to http://<host>:<port>/__admin/socket-delay:

{ "milliseconds": 300 }

(Obviously replacing 300 with however many milliseconds you'd like to delay by)

like image 139
Tom Avatar answered Sep 27 '22 17:09

Tom


It seems that the answer to this question has been "No", since version 2.0.8-beta.

Tom (author of WireMock) explains why in this GitHub issue:

It's basically impossible to reliably force connection timeouts in pure Java at the moment.

It used to be the case that you could inject a delay before calling .accept() on the socket, but that stopped working a while back, I guess due to a change in the implementation internals.

My recommendation at the moment would be to use a tool that works at the level of the network stack. iptables ... -j DROP type commands will do the trick, or if you want a level of automation over this you can use tools such as https://github.com/tomakehurst/saboteur or https://github.com/alexei-led/pumba.

He also goes on to explain that just stopping WireMock doesn't achieve the same thing:

shutting down WireMock won't have the same effect - when a port is not being listened on, you get a TCP RST (reset) packet back, whereas a connection timeout happens when you get nothing back from the server in the timeout window after your initial SYN packet.

like image 26
DaveyDaveDave Avatar answered Sep 27 '22 17:09

DaveyDaveDave