Question

I have a network C++ program in Windows that I'd like to test for network disconnects at various times. What are my options?

Currently I am:

  1. Actually disconnecting the network wire from the back of my computer
  2. using ipconfig /release
  3. Using the cports program to close out the socket completely

None of these methods though are ideal for me, and I'd like to emulate network problems more easily.

I would like for sometimes connects to fail, sometimes socket reads to fail, and sometimes socket writes to fail. It would be great if there was some utility I could use to emulate these types of problems.

It would also be nice to be able to build some automated unit tests while this emulated bad network is up.

Was it helpful?

Solution

You might want to abstract the network layer, and then you can have unit tests that inject interesting failure events at appropriate points.

OTHER TIPS

The closest I can think of is doing something similar with VEDekstop from Shunra..

Simulating High Latency and Low Bandwidth in Testing of Database Applications

Shunra VE Desktop Standard is a Windows-based client software solution that simulates a wide area network link so that you can test applications under a variety of current and potential network conditions – directly from your desktop.

You can subclass whatever library class you are using to manage your sockets (presumably CAsyncSocket or CSocket if you are using MFC), override the methods whose failure you want to test, and insert appropriate test code in your overrides.

There are some methods you can use, it is depend on which level you want to test. For function level, you can use XUNIT testing framework to mock a responce. For software level, you can use a local proxy server to contral connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top