Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?

share|improve this question

closed as off-topic by Snowman, GlenH7, gnat, Ixrec, MichaelT Apr 20 at 13:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Snowman, GlenH7, MichaelT
If this question can be reworded to fit the rules in the help center, please edit the question.

    
software recommendations are explicitly off-topic per help center (it's the same here as at Stack Overflow). See meta.programmers.stackexchange.com/questions/6483/… –  gnat Apr 17 at 12:56
    
@gnat Do you have a recommendation as to where I can ask a question like this? (I do believe that questions like this are relevant to the job of programming. Often the answers to queries of this kind can be invaluable.) –  RenniePet Apr 17 at 13:02
    
did you check meta guidance referred in prior comment? There's a section called: "Is there a place where I can ask such questions?" –  gnat Apr 17 at 13:03
    
@gnat: OK, I'll try posting at Software Recommendations. But as well as asking about testing tools, a possible answer could be that the best solution is that I implement the test code as a part of my own program, so then we're presumably in the "quality assurance and testing" area, which is on-topic here? –  RenniePet Apr 17 at 13:13
    
well per my reading, software recommendation makes only a small part here ("if there is some... program"); the rest looks like a reasonable question for this site –  gnat Apr 17 at 17:54

3 Answers 3

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

share|improve this answer
    
Thanks, I'll look into these. –  RenniePet Apr 18 at 2:17

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.

share|improve this answer
    
Thanks for your answer. I'm not familiar with the concept of "mocking" a client or server, I'll have to do some research. –  RenniePet Apr 18 at 2:18
    
"mocking" the client or server is simply creating a test client and/or server that specifically performs the types of tests you wish to perform. It can even be your exact application code with the slight modification to instill errors/conditions that you wish to test for. –  Dunk Apr 22 at 16:22

Beyond mocking the network interface, you don't need two physical machines for a system test:

  1. Disable/reenable the network card using scripts that do ifconfig/ipconfig.
  2. 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.

share|improve this answer
    
Thanks. The idea of putting one end in a virtual machine and starting and stopping it is interesting. –  RenniePet Apr 18 at 2:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.