I've had a bug in our software that occurs when I receive a connection timeout. These errors are very rare (usually when my connection gets dropped by our internal network). How can I generate this kind of effect artificially so I can test our software?
If it matters the app is written in C++/MFC using CAsyncSocket classes.
Edit:
I've tried using a non-existent host, and I get the socket error:
WSAEINVAL (10022) Invalid argument
My next attempt was to use Alexander's suggestion of connecting to a different port, e.g. 81 (on my own server though). That worked great. Exactly the same as a dropped connection (60 second wait, then error). Thank you!
Despite it isn't completely clear which one the OP wants to test: there's a difference between attempting a connection to a non-existent host/port and a timeout of an already established connection. I would go with Rob and wait until the connection is working and then pull the cable. Or - for convenience - have a virtual machine working as the test server (with bridged networking) and just deactivating the virtual network interface once the connection is established.
Plug in your network cable into a switch which has no other connection/cables. That should work imho.
You can try to connect to one of well-known Web sites on a port that may not be available from outside - 200 for example. Most of firewalls work in DROP mode and it will simulate a timeout for you.
The following URL always gives a timeout, and combines the best of @Alexander and @Emu's answers above:
http://example.com:81
Using
example.com:81
is an improvement on Alexander's answer because example.com is reserved by the DNS standard, so it will always be unreachable, unlikegoogle.com:81
, which may change if Google feels like it. Also, becauseexample.com
is defined to be unreachable, you won't be flooding Google's servers.I'd say it's an improvement over @emu's answer because it's a lot easier to remember.
Plenty of good answers but the cleanest solution seems to be this service
http://httpstat.us/504?sleep=60000
You can configure the timeout duration (up to 230 seconds) and eventual return code.
If you are on a unix machine, you can start a port listening using netcat:
Then, modify you service to call whatever it usually does to that port e.g. http://localhost:8099/some/sort/of/endpoint
Then, your service will open the connection and write data, but will never get a response, and so will give you a Read Time Out (rather than Connection Refused)