I know that it can simulate SocketTimeoutException
by using withFixedDelay
, but what about ConnectionTimeoutException
?
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)
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 initialSYN
packet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With