testing socket timeouts

A while ago I wrote about a test server I had written to help test our systems against their external dependencies. And it has proved very useful.

This week I was once again working on improvements to our external transaction handling, and while my test server was useful, we also wanted to test against the customer’s server, but still create error conditions on demand.

I looked around for tools, but didn’t really find any that would do what we wanted. Who knows, maybe I just didn’t look far enough? I did try out Shunra Desktop but the evaluation version didn’t cause enough problems to disturb our application.

So I ended up writing my own tool in Java1. It acts as a kind of proxy at the socket level, so the application connects to it, and it connects to the real endpoint. Once I’d got a basic pass-through connection working, I added a class that instead of just passing through the data, it sticks it in a DelayQueue with a time attached to it2. It then has a separate thread to get the data out of the queue once the time has passed, and send it on through to the receiver.

By setting up this tool with pass-through on the outward path, but a delay on the return path, I can exactly recreate the problem we have seen in production, where a request gets to the external system ok, but the response times out. Handy. I have some thoughts about modifying the tool to add things like logging the data too.


1 Given my recent enthusiasm, you might think I would want to write it in Ruby. But actually Ruby’s socket and thread libraries are a bit clunky, whereas Java’s are well suited for what I want to do, and besides which I know them a lot better.

2 I love the java.util.concurrent package; I’m not sure how we lived without it.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*