Your Linux Data Center Experts

I've been working on the next generation memcached module for Python, and it includes extensive tests. One of the things I wanted to test was what happened when the Memcache server unexpectedly dies.

Rather than using Mocks, I wanted to have my code connect to a real server that was misbehaving. So I created a class that you can give a simple expect/send program to, and it forks off and runs a server for a few seconds, then exits. The program is a list, with None indicating that it should receive data from the client, and a string indicating something to send.

This allowed me to track down a number of exceptions that I wasn't catching in my high-level wrapper code that treats exceptions as cache misses. Fantastically useful!

I've published this code to my unittest skeleton code repository. Here's a simple example:

from mctestsupp import RECEIVE, CommandServer

immediately_disconnect_server = CommandServer([])
sc = memcached2.ServerConnection('memcached://{0}/'
with self.assertRaises(memcached2.ServerDisconnect):
            memcache.set('foo', 'bar')

That also has a skeleton for testing Bottle web apps super easily. I've been using Bottle a lot lately for simple little web control panel type apps.

comments powered by Disqus

Join our other satisfied clients. Contact us today.