I’ve written my own C# TCP communications module (using SocketAsyncEventArgs, although that’s presumably irrelevant). My module runs at both ends of the connection, client and server. As part of the programming it is supposed to detect when the connection fails, and then automatically try to reestablish the connection.
I’d like to hear idea about how to test this. One solution is to run it on two physical machines and unplug the network cable for a while and then reconnect. This isn’t very automated.
I’m wondering if there is some kind of WinSock hook program that can be used to simulate connection failures? Or any other suggestions?
5
First, I think this is a perfectly good question. It’s an interesting area and i don’t get why was this downvoted.
You don’t need winsock you can disable the network a adapter and change it’s settings programmatically… but network issues could be very tricky to simulate this way…
https://code.msdn.microsoft.com/windowsapps/Disableenable-network-8112f642
I’m assuming this is an integration test of some sort….
What I would do is make a small component to function as a proxy bridge. So that the tested app will talk to the bridge, and the “bridge” would transfer it’s traffic to wherever it was intended. Then you can use the “bridge” app to simulate any kind of network issue you may need i.e. latency, jitter, lost packets, disconnects…
There are tools for this you should look up before writing your own…
http://jagt.github.io/clumsy/
https://github.com/tylertreat/Comcast
0
You test these by mocking the client and server and using IP Address 127.0.0.1
Depending on the test you are performing, it could be a simple matter of having the mock-server simply closing its end of the connection after some predefined time and then verifying that the client reconnected within the specified time-frame.
It may be difficult to test some of the possible error conditions that could occur at the TCP and IP layers but most of those errors you don’t care about anyways, as your main concern is handling errors that are reported by the higher level socket interface. So being able to automatically create any one of similar low level errors will be an adequate test for your application level unit test.
2
Beyond mocking the network interface, you don’t need two physical machines for a system test:
- Disable/reenable the network card using scripts that do ifconfig/ipconfig.
- use a virtual machine for one end of the system and script it up/down or enable/disable the networking.
Hooking into WinSock is way more work than you need to do here.
1