Creating TCP network errors for unit testing

Posted by Robert S. Barnes on Stack Overflow See other posts from Stack Overflow or by Robert S. Barnes
Published on 2010-06-18T06:19:09Z Indexed on 2010/06/18 6:23 UTC
Read the original article Hit count: 206

Filed under:
|
|
|
|

I'd like to create various network errors during testing. I'm using the Berkely sockets API directly in C++ on Linux. I'm running a mock server in another thread from within Boost.Test which listens on localhost.

For instance, I'd like to create a timeout during connect. So far I've tried not calling accept in my mock server and setting the backlog to 1, then making multiple connections, but all seem to successfully connect. I would think that if there wasn't room in the backlog queue I would at least get a connection refused error if not a timeout.

I'd like to do this all programatically if possible, but I'd consider using something external like IPchains to intentionally drop certain packets to certain ports during testing, but I'd need to automate creating and removing rules so I could do it from within my Boost.Test unit tests.

I suppose I could mock the various system calls involved, but I'd rather go through a real TCP stack if possible.

Ideas?

© Stack Overflow or respective owner

Related posts about c++

Related posts about unit-testing